+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.data.ArrayReader\r
- * @extends Ext.data.JsonReader\r
- * Data reader class to create an Array of {@link Ext.data.Record} objects from an Array.\r
- * Each element of that Array represents a row of data fields. The\r
- * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property\r
- * of the field definition if it exists, or the field's ordinal position in the definition.<br>\r
- * <p>\r
- * Example code:.\r
- * <pre><code>\r
-var Employee = Ext.data.Record.create([\r
- {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which\r
- {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.\r
-]);\r
-var myReader = new Ext.data.ArrayReader({\r
- id: 0 // The subscript within row Array that provides an ID for the Record (optional)\r
-}, Employee);\r
-</code></pre>\r
- * <p>\r
- * This would consume an Array like this:\r
- * <pre><code>\r
-[ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]\r
- </code></pre>\r
- * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record\r
- * @constructor\r
- * Create a new ArrayReader\r
- * @param {Object} meta Metadata configuration options.\r
- * @param {Object} recordType Either an Array of field definition objects\r
- * as specified to {@link Ext.data.Record#create},\r
- * or a {@link Ext.data.Record Record} constructor\r
- * created using {@link Ext.data.Record#create}.\r
- */\r
-Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {\r
- /**\r
- * Create a data block containing Ext.data.Records from an Array.\r
- * @param {Object} o An Array of row objects which represents the dataset.\r
- * @return {Object} data A data block which is used by an Ext.data.Store object as\r
- * a cache of Ext.data.Records.\r
- */\r
- readRecords : function(o){\r
- var sid = this.meta ? this.meta.id : null;\r
- var recordType = this.recordType, fields = recordType.prototype.fields;\r
- var records = [];\r
- var root = o;\r
- for(var i = 0; i < root.length; i++){\r
- var n = root[i];\r
- var values = {};\r
- var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);\r
- for(var j = 0, jlen = fields.length; j < jlen; j++){\r
- var f = fields.items[j];\r
- var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;\r
- var v = n[k] !== undefined ? n[k] : f.defaultValue;\r
- v = f.convert(v, n);\r
- values[f.name] = v;\r
- }\r
- var record = new recordType(values, id);\r
- record.json = n;\r
- records[records.length] = record;\r
- }\r
- return {\r
- records : records,\r
- totalRecords : records.length\r
- };\r
- }\r
-});
\ No newline at end of file