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