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