Alien-Web-ExtJS-V3

 view release on metacpan or  search on metacpan

share/docs/source/DataReader.html  view on Meta::CPAN

                else {
                    // weird...rs is an array but data isn't??  recurse but just send in the whole data object.
                    // the else clause below will detect !this.isData and throw exception.
                    this.update(rs.splice(i,1).shift(), data);
                }
            }
        }
        else {
            // If rs is NOT an array but data IS, see if data contains just 1 record.  If so extract it and carry on.
            if (Ext.isArray(data) && data.length == 1) {
                data = data.shift();
            }
            if (this.isData(data)) {
                rs.data = Ext.apply(rs.data, data);
            }
            rs.commit();
        }
    },

<span id='Ext-data-DataReader-method-extractData'>    /**
</span>     * returns extracted, type-cast rows of data.  Iterates to call #extractValues for each row
     * @param {Object[]/Object} data-root from server response
     * @param {Boolean} returnRecords [false] Set true to return instances of Ext.data.Record
     * @private
     */
    extractData : function(root, returnRecords) {
        // A bit ugly this, too bad the Record's raw data couldn't be saved in a common property named &quot;raw&quot; or something.
        var rawName = (this instanceof Ext.data.JsonReader) ? 'json' : 'node';

        var rs = [];

        // Had to add Check for XmlReader, #isData returns true if root is an Xml-object.  Want to check in order to re-factor
        // #extractData into DataReader base, since the implementations are almost identical for JsonReader, XmlReader
        if (this.isData(root) &amp;&amp; !(this instanceof Ext.data.XmlReader)) {
            root = [root];
        }
        var f       = this.recordType.prototype.fields,
            fi      = f.items,
            fl      = f.length,
            rs      = [];
        if (returnRecords === true) {
            var Record = this.recordType;
            for (var i = 0; i &lt; root.length; i++) {
                var n = root[i];
                var record = new Record(this.extractValues(n, fi, fl), this.getId(n));
                record[rawName] = n;    // &lt;-- There's implementation of ugly bit, setting the raw record-data.
                rs.push(record);
            }
        }
        else {
            for (var i = 0; i &lt; root.length; i++) {
                var data = this.extractValues(root[i], fi, fl);
                data[this.meta.idProperty] = this.getId(root[i]);
                rs.push(data);
            }
        }
        return rs;
    },

<span id='Ext-data-DataReader-method-isData'>    /**
</span>     * Returns true if the supplied data-hash &lt;b&gt;looks&lt;/b&gt; and quacks like data.  Checks to see if it has a key
     * corresponding to idProperty defined in your DataReader config containing non-empty pk.
     * @param {Object} data
     * @return {Boolean}
     */
    isData : function(data) {
        return (data &amp;&amp; Ext.isObject(data) &amp;&amp; !Ext.isEmpty(this.getId(data))) ? true : false;
    },

    // private function a store will createSequence upon
    onMetaChange : function(meta){
        delete this.ef;
        this.meta = meta;
        this.recordType = Ext.data.Record.create(meta.fields);
        this.buildExtractors();
    }
};

<span id='Ext-data-DataReader-Error'>/**
</span> * @class Ext.data.DataReader.Error
 * @extends Ext.Error
 * General error class for Ext.data.DataReader
 */
Ext.data.DataReader.Error = Ext.extend(Ext.Error, {
<span id='Ext-data-DataReader-Error-method-constructor'>    constructor : function(message, arg) {
</span>        this.arg = arg;
        Ext.Error.call(this, message);
    },
<span id='Ext-data-DataReader-Error-property-name'>    name: 'Ext.data.DataReader'
</span>});
Ext.apply(Ext.data.DataReader.Error.prototype, {
    lang : {
        'update': &quot;#update received invalid data from server.  Please see docs for DataReader#update and review your DataReader configuration.&quot;,
        'realize': &quot;#realize was called with invalid remote-data.  Please see the docs for DataReader#realize and review your DataReader configuration.&quot;,
        'invalid-response': &quot;#readResponse received an invalid response from the server.&quot;
    }
});
</pre>
</body>
</html>



( run in 0.781 second using v1.01-cache-2.11-cpan-02777c243ea )