3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * @class Ext.data.ArrayReader
9 * @extends Ext.data.JsonReader
10 * <p>Data reader class to create an Array of {@link Ext.data.Record} objects from an Array.
11 * Each element of that Array represents a row of data fields. The
12 * fields are pulled into a Record object using as a subscript, the <code>mapping</code> property
13 * of the field definition if it exists, or the field's ordinal position in the definition.</p>
14 * <p>Example code:</p>
16 var Employee = Ext.data.Record.create([
17 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
18 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
20 var myReader = new Ext.data.ArrayReader({
24 * <p>This would consume an Array like this:</p>
26 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
29 * Create a new ArrayReader
30 * @param {Object} meta Metadata configuration options.
31 * @param {Array/Object} recordType
32 * <p>Either an Array of {@link Ext.data.Field Field} definition objects (which
33 * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record}
34 * constructor created from {@link Ext.data.Record#create}.</p>
36 Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {
38 * @cfg {String} successProperty
42 * @cfg {Number} id (optional) The subscript within row Array that provides an ID for the Record.
43 * Deprecated. Use {@link #idIndex} instead.
46 * @cfg {Number} idIndex (optional) The subscript within row Array that provides an ID for the Record.
49 * Create a data block containing Ext.data.Records from an Array.
50 * @param {Object} o An Array of row objects which represents the dataset.
51 * @return {Object} data A data block which is used by an Ext.data.Store object as
52 * a cache of Ext.data.Records.
54 readRecords : function(o){
57 sid = s ? Ext.num(s.idIndex, s.id) : null,
58 recordType = this.recordType,
59 fields = recordType.prototype.fields,
64 var root = this.getRoot(o);
66 for(var i = 0, len = root.length; i < len; i++) {
69 id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
70 for(var j = 0, jlen = fields.length; j < jlen; j++) {
71 var f = fields.items[j],
72 k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
73 v = n[k] !== undefined ? n[k] : f.defaultValue;
77 var record = new recordType(values, id);
79 records[records.length] = record;
82 var totalRecords = records.length;
85 v = parseInt(this.getTotal(o), 10);
90 if(s.successProperty){
91 v = this.getSuccess(o);
92 if(v === false || v === 'false'){
100 totalRecords : totalRecords