X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..2e847cf21b8ab9d15fa167b315ca5b2fa92638fc:/src/data/JsonReader.js?ds=inline diff --git a/src/data/JsonReader.js b/src/data/JsonReader.js index fa537347..3da7fbb6 100644 --- a/src/data/JsonReader.js +++ b/src/data/JsonReader.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.3 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.1.1 + * Copyright(c) 2006-2010 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ @@ -193,7 +193,7 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, { var res = new Ext.data.Response({ action: action, success: this.getSuccess(o), - data: this.extractData(root), + data: (root) ? this.extractData(root, false) : [], message: this.getMessage(o), raw: o }); @@ -298,50 +298,22 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, { createAccessor : function(){ var re = /[\[\.]/; return function(expr) { - try { - return(re.test(expr)) ? - new Function('obj', 'return obj.' + expr) : - function(obj){ - return obj[expr]; - }; - } catch(e){} - return Ext.emptyFn; - }; - }(), - - /** - * 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) { - var rs = undefined; - if (this.isData(root)) { - root = [root]; - } - if (Ext.isArray(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 < root.length; i++) { - var n = root[i]; - var record = new Record(this.extractValues(n, fi, fl), this.getId(n)); - record.json = n; - rs.push(record); - } + if(Ext.isEmpty(expr)){ + return Ext.emptyFn; } - else { - for (var i = 0; i < root.length; i++) { - rs.push(this.extractValues(root[i], fi, fl)); - } + if(Ext.isFunction(expr)){ + return expr; } - } - return rs; - }, + var i = String(expr).search(re); + if(i >= 0){ + return new Function('obj', 'return obj' + (i > 0 ? '.' : '') + expr); + } + return function(obj){ + return obj[expr]; + }; + + }; + }(), /** * type-casts a single row of raw-data from server