我在使用 Ext.data.JsonReader 映射 Ext.data.JsonStore 模型时遇到问题。
来自服务器的 Json 响应(服务器模型):
{"rows":[{"id":1,"firstname":"Bill"},{"id": 2,"firstname":"Ben"}]}
Json Store 中使用的模型:
Ext.regModel( 'mycabinet', {
fields: [
{ name : 'DeviceId', type: 'int' },
'CabinetName']
});
json阅读器代码:
var iccDeviceReader = new Ext.data.JsonReader({
// metadata configuration options:
idProperty: 'id',
root: 'rows',
fields: [
{name: 'CabinetName', mapping: 'firstname'},
{name:'DeviceId',mapping:'id'}
]
});
json存储代码:
app.iccDS = new Ext.data.JsonStore( {
model : 'mycabinet',
sorters : 'CabinetName',
getGroupString : function(record) { return record.get('CabinetName')[0]; },
proxy : {
type: 'ajax',
url : '/icc/js/data.js',
reader:iccDeviceReader
},
autoLoad: true
} );
我期待“mycabinet”模型将填充“服务器模型”。但是,映射不会发生。我什至尝试使用 convert 没有任何成功(name:'DeviceId',mapping:'id',convert: function(v){return v.id;})
任何帮助将不胜感激。谢谢