2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.data.ArrayReader
\r
11 * @extends Ext.data.JsonReader
\r
12 * Data reader class to create an Array of {@link Ext.data.Record} objects from an Array.
\r
13 * Each element of that Array represents a row of data fields. The
\r
14 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
\r
15 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
\r
19 var Employee = Ext.data.Record.create([
\r
20 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
\r
21 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
\r
23 var myReader = new Ext.data.ArrayReader({
\r
24 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
\r
28 * This would consume an Array like this:
\r
30 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
\r
32 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
\r
34 * Create a new ArrayReader
\r
35 * @param {Object} meta Metadata configuration options.
\r
36 * @param {Object} recordType Either an Array of field definition objects
\r
37 * as specified to {@link Ext.data.Record#create},
\r
38 * or a {@link Ext.data.Record Record} constructor
\r
39 * created using {@link Ext.data.Record#create}.
\r
41 Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {
\r
43 * Create a data block containing Ext.data.Records from an Array.
\r
44 * @param {Object} o An Array of row objects which represents the dataset.
\r
45 * @return {Object} data A data block which is used by an Ext.data.Store object as
\r
46 * a cache of Ext.data.Records.
\r
48 readRecords : function(o){
\r
49 var sid = this.meta ? this.meta.id : null;
\r
50 var recordType = this.recordType, fields = recordType.prototype.fields;
\r
53 for(var i = 0; i < root.length; i++){
\r
56 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
\r
57 for(var j = 0, jlen = fields.length; j < jlen; j++){
\r
58 var f = fields.items[j];
\r
59 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
\r
60 var v = n[k] !== undefined ? n[k] : f.defaultValue;
\r
61 v = f.convert(v, n);
\r
64 var record = new recordType(values, id);
\r
66 records[records.length] = record;
\r
70 totalRecords : records.length
\r