SimpleStore 的reader 配置属性有用吗
zzhdi
2009-03-15
请看下面的代码 var data = [[1, 'AL', '0.1', 'The Heart of Dixie', '6', new Date()]] var rec = new Ext.data.Record.create([{ name: 'company', mapping: 1 }, { name: 'price', mapping: 2 }, { name: 'change', mapping: 3 }, { name: 'pctChange', mapping: 4 }, { name: 'lastChange', mapping: 5 }]); var store = new Ext.data.SimpleStore({ fields: ['pid','company','price', 'change', 'pctChange', 'lastChange'], data: data, reader: new Ext.data.ArrayReader({id: 0}, rec) }); alert(store.getAt(0).get('company'));// 'AL' 上面的代码运行正确,但我把 company 的mapping值设为2 ,price 的mapping设置为 1 后,但 alert(store.getAt(0).get('company')); 的执行结果仍然是 'AL' ,只有把 变量store 的fields 属性配置为 ['pid','price', 'company', 'change', 'pctChange', 'lastChange'] 后 alert(store.getAt(0).get('company')); 的执行结果才是 '0.1' 再者 store变量的 reader属性中,配置了 id:0 但是 alert(store.getById(1).get('name)) 却出现错误:store.getById(0) is undefined 查看SimpleStore.js 文件发现Simple的定义是这样的
Ext.data.SimpleStore = function(config){ Ext.data.SimpleStore.superclass.constructor.call(this, Ext.apply(config, { reader: new Ext.data.ArrayReader({ id: config.id }, Ext.data.Record.create(config.fields) ) })); }; 由此我是否可以认为为SimpleStore配置reader属性是没有用处的? 我使用的ExtJs的版本是 2.2.1 |