Array3.html 3.36 KB
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-data-reader-Array-method-constructor'><span id='Ext-data-reader-Array'>/**
</span></span> * @author Ed Spencer
 * @class Ext.data.reader.Array
 * 
 * &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',

    // For Array Reader, methods in the base which use these properties must not see the defaults
    totalProperty: undefined,
    successProperty: undefined,

<span id='Ext-data-reader-Array-method-createFieldAccessExpression'>    /**
</span>     * @private
     * Returns an accessor expression for the passed Field from an Array using either the Field's mapping, or
     * its ordinal position in the fields collsction as the index.
     * This is used by buildExtractors to create optimized on extractor function which converts raw data into model instances.
     */
    createFieldAccessExpression: function(field, fieldVarName, dataName) {
            // In the absence of a mapping property, use the original ordinal position
            // at which the Model inserted the field into its collection.
        var index  = (field.mapping == null) ? field.originalIndex : field.mapping,
            result;

        if (typeof index === 'function') {
            result = fieldVarName + '.mapping(' + dataName + ', this)';
        } else {
            if (isNaN(index)) {
                index = '&quot;' + index + '&quot;';
            }
            result = dataName + &quot;[&quot; + index + &quot;]&quot;;
        }
        return result;
    }
});
</pre>
</body>
</html>