官方提交bug详情:Ext.data.ArrayReader.readRecords have a bug when mapping 'prop1.propNext'
* Ext 3.2.0
Adapter used:
* ext
css used:
* only default ext-all.css
Browser versions tested against:
* FF3 (firebug installed)
Operating System:
* ubuntu 9.10 64bit
Description:
* Ext.data.ArrayReader.readRecords have a bug when mapping 'prop1.propNext'
Test Case:
var record = Ext.data.Record.create([ {name: 'id', mapping: 'id'}, {name: 'name', mapping: 'text'}, {name: 'info', mapping: 'userData.info'}, {name: 'order', mapping: 'userData.order'} ]); var store = new Ext.data.Store({sortInfo: {field: 'order'}, reader: new Ext.data.ArrayReader({id: 'id'}, record)}) var win = new Ext.Window({ closable: false, layout: 'fit', width: 700, height: 400, items: [{ xtype: 'grid', title: ' ', iconCls: 'x-tree-node-icon-folder', tbar: ['-', {text: 'refresh'}, '-', '->'], columns: [ {header: 'ID', dataIndex: 'id', menuDisabled: true, hidden: true, width: 40, sortable: true, align: 'right'}, {header: 'name', dataIndex: 'name', hideable: false, width: 80, sortable: true}, {header: 'info', dataIndex: 'info', width: 100, sortable: true}, {header: 'order', dataIndex: 'order', width: 40, sortable: true, menuDisabled: true} ], store: store }] }); win.show(); var datas = []; for (var i = 0; i < 10; i++) { datas[i] = {id: i, text: 'text' + i, userData: {info: 'info' + i, order: i % 5}}; } store.loadData(datas);
var record = Ext.data.Record.create([
{name: 'id', mapping: 'id'},
{name: 'name', mapping: 'text'},
{name: 'info', mapping: 'userData.info'},//根据mapping的定义是支持这样映射的
{name: 'order', mapping: 'userData.order'}//not any effect too
]);
My fix:
the right code is:
var records = this.extractData(this.getRoot(o), true);
if (Ext.version == '3.2.0') { Ext.apply(Ext.data.ArrayReader.prototype, { readRecords : function(o){ this.arrayData = o; var s = this.meta, success = true, v; var records = this.extractData(this.getRoot(o), true); var totalRecords = records.length; if(s.totalProperty) { v = parseInt(this.getTotal(o), 10); if(!isNaN(v)) { totalRecords = v; } } if(s.successProperty){ v = this.getSuccess(o); if(v === false || v === 'false'){ success = false; } } return { success : success, records : records, totalRecords : totalRecords }; } }); }