3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">/*!
10 * Copyright(c) 2006-2009 Ext JS, LLC
12 * http://www.extjs.com/license
14 <div id="cls-Ext.data.ArrayReader"></div>/**
15 * @class Ext.data.ArrayReader
16 * @extends Ext.data.JsonReader
17 * <p>Data reader class to create an Array of {@link Ext.data.Record} objects from an Array.
18 * Each element of that Array represents a row of data fields. The
19 * fields are pulled into a Record object using as a subscript, the <code>mapping</code> property
20 * of the field definition if it exists, or the field's ordinal position in the definition.</p>
21 * <p>Example code:</p>
23 var Employee = Ext.data.Record.create([
24 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
25 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
27 var myReader = new Ext.data.ArrayReader({
31 * <p>This would consume an Array like this:</p>
33 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
36 * Create a new ArrayReader
37 * @param {Object} meta Metadata configuration options.
38 * @param {Array/Object} recordType
39 * <p>Either an Array of {@link Ext.data.Field Field} definition objects (which
40 * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record}
41 * constructor created from {@link Ext.data.Record#create}.</p>
43 Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {
44 <div id="cfg-Ext.data.ArrayReader-successProperty"></div>/**
45 * @cfg {String} successProperty
48 <div id="cfg-Ext.data.ArrayReader-id"></div>/**
49 * @cfg {Number} id (optional) The subscript within row Array that provides an ID for the Record.
50 * Deprecated. Use {@link #idIndex} instead.
52 <div id="cfg-Ext.data.ArrayReader-idIndex"></div>/**
53 * @cfg {Number} idIndex (optional) The subscript within row Array that provides an ID for the Record.
55 <div id="method-Ext.data.ArrayReader-readRecords"></div>/**
56 * Create a data block containing Ext.data.Records from an Array.
57 * @param {Object} o An Array of row objects which represents the dataset.
58 * @return {Object} data A data block which is used by an Ext.data.Store object as
59 * a cache of Ext.data.Records.
61 readRecords : function(o){
64 sid = s ? Ext.num(s.idIndex, s.id) : null,
65 recordType = this.recordType,
66 fields = recordType.prototype.fields,
71 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p) {return p;};
73 this.getTotal = this.getJsonAccessor(s.totalProperty);
77 var root = this.getRoot(o);
79 for(var i = 0, len = root.length; i < len; i++) {
82 id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
83 for(var j = 0, jlen = fields.length; j < jlen; j++) {
84 var f = fields.items[j],
85 k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
86 v = n[k] !== undefined ? n[k] : f.defaultValue;
90 var record = new recordType(values, id);
92 records[records.length] = record;
95 var totalRecords = records.length;
98 v = parseInt(this.getTotal(o), 10);
106 totalRecords : totalRecords