3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.data.ArrayReader"></div>/**
10 * @class Ext.data.ArrayReader
11 * @extends Ext.data.JsonReader
12 * <p>Data reader class to create an Array of {@link Ext.data.Record} objects from an Array.
13 * Each element of that Array represents a row of data fields. The
14 * fields are pulled into a Record object using as a subscript, the <code>mapping</code> property
15 * of the field definition if it exists, or the field's ordinal position in the definition.</p>
16 * <p>Example code:</p>
18 var Employee = Ext.data.Record.create([
19 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
20 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
22 var myReader = new Ext.data.ArrayReader({
26 * <p>This would consume an Array like this:</p>
28 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
31 * Create a new ArrayReader
32 * @param {Object} meta Metadata configuration options.
33 * @param {Array/Object} recordType
34 * <p>Either an Array of {@link Ext.data.Field Field} definition objects (which
35 * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record}
36 * constructor created from {@link Ext.data.Record#create}.</p>
38 Ext.data.ArrayReader = Ext.extend(Ext.data.JsonReader, {
39 <div id="cfg-Ext.data.ArrayReader-successProperty"></div>/**
40 * @cfg {String} successProperty
43 <div id="cfg-Ext.data.ArrayReader-id"></div>/**
44 * @cfg {Number} id (optional) The subscript within row Array that provides an ID for the Record.
45 * Deprecated. Use {@link #idIndex} instead.
47 <div id="cfg-Ext.data.ArrayReader-idIndex"></div>/**
48 * @cfg {Number} idIndex (optional) The subscript within row Array that provides an ID for the Record.
50 <div id="method-Ext.data.ArrayReader-readRecords"></div>/**
51 * Create a data block containing Ext.data.Records from an Array.
52 * @param {Object} o An Array of row objects which represents the dataset.
53 * @return {Object} data A data block which is used by an Ext.data.Store object as
54 * a cache of Ext.data.Records.
56 readRecords : function(o){
59 sid = s ? Ext.num(s.idIndex, s.id) : null,
60 recordType = this.recordType,
61 fields = recordType.prototype.fields,
66 var root = this.getRoot(o);
68 for(var i = 0, len = root.length; i < len; i++) {
71 id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
72 for(var j = 0, jlen = fields.length; j < jlen; j++) {
73 var f = fields.items[j],
74 k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
75 v = n[k] !== undefined ? n[k] : f.defaultValue;
79 var record = new recordType(values, id);
81 records[records.length] = record;
84 var totalRecords = records.length;
87 v = parseInt(this.getTotal(o), 10);
92 if(s.successProperty){
93 v = this.getSuccess(o);
94 if(v === false || v === 'false'){
102 totalRecords : totalRecords