Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / source / Array.html
diff --git a/docs/source/Array.html b/docs/source/Array.html
new file mode 100644 (file)
index 0000000..e51b813
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.reader.Array-method-constructor'><span id='Ext-data.reader.Array'>/**
+</span></span> * @author Ed Spencer
+ * @class Ext.data.reader.Array
+ * @extends Ext.data.reader.Json
+ * 
+ * &lt;p&gt;Data reader class to create an Array of {@link Ext.data.Model} objects from an Array.
+ * Each element of that Array represents a row of data fields. The
+ * fields are pulled into a Record object using as a subscript, the &lt;code&gt;mapping&lt;/code&gt; property
+ * of the field definition if it exists, or the field's ordinal position in the definition.&lt;/p&gt;
+ * 
+ * &lt;p&gt;&lt;u&gt;Example code:&lt;/u&gt;&lt;/p&gt;
+ * 
+&lt;pre&gt;&lt;code&gt;
+Employee = Ext.define('Employee', {
+    extend: 'Ext.data.Model',
+    fields: [
+        'id',
+        {name: 'name', mapping: 1},         // &quot;mapping&quot; only needed if an &quot;id&quot; field is present which
+        {name: 'occupation', mapping: 2}    // precludes using the ordinal position as the index.        
+    ]
+});
+
+var myReader = new Ext.data.reader.Array({
+    model: 'Employee'
+}, Employee);
+&lt;/code&gt;&lt;/pre&gt;
+ * 
+ * &lt;p&gt;This would consume an Array like this:&lt;/p&gt;
+ * 
+&lt;pre&gt;&lt;code&gt;
+[ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
+&lt;/code&gt;&lt;/pre&gt;
+ * 
+ * @constructor
+ * Create a new ArrayReader
+ * @param {Object} meta Metadata configuration options.
+ */
+Ext.define('Ext.data.reader.Array', {
+    extend: 'Ext.data.reader.Json',
+    alternateClassName: 'Ext.data.ArrayReader',
+    alias : 'reader.array',
+
+<span id='Ext-data.reader.Array-method-buildExtractors'>    /**
+</span>     * @private
+     * Most of the work is done for us by JsonReader, but we need to overwrite the field accessors to just
+     * reference the correct position in the array.
+     */
+    buildExtractors: function() {
+        this.callParent(arguments);
+        
+        var fields = this.model.prototype.fields.items,
+            length = fields.length,
+            extractorFunctions = [],
+            i;
+        
+        for (i = 0; i &lt; length; i++) {
+            extractorFunctions.push(function(index) {
+                return function(data) {
+                    return data[index];
+                };
+            }(fields[i].mapping || i));
+        }
+        
+        this.extractorFunctions = extractorFunctions;
+    }
+});
+</pre></pre></body></html>
\ No newline at end of file