0

我在使用 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;})

任何帮助将不胜感激。谢谢

4

2 回答 2

0

从阅读器中删除“字段”选项,并在模型配置中将'CabinetName'更改为{name: 'CabinetName', mapping: 'firstname'}。此外,idProperty也应该进入您的模型配置。

于 2011-10-05T18:09:28.543 回答
0

以下代码解决了我的问题...

Ext.regModel( 'mycabinet', {
fields: [ 
{ name : 'DeviceId', type: 'int',mapping:'id' },
{name: 'CabinetName', mapping: 'firstname'}]
});

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'
},
autoLoad: true
} );

我不再使用 jsonReader。

于 2011-10-06T06:01:11.697 回答