Mapping 无法使用Sencha Touch中的JsonReader在JsonStore中映射模型
在使用Ext.data.JsonReader映射Ext.data.JsonStore模型时,我在sencha中遇到了一个问题 来自服务器的Json响应(服务器型号): Json存储中使用的模型:Mapping 无法使用Sencha Touch中的JsonReader在JsonStore中映射模型,mapping,sencha-touch,jsonstore,jsonreader,Mapping,Sencha Touch,Jsonstore,Jsonreader,在使用Ext.data.JsonReader映射Ext.data.JsonStore模型时,我在sencha中遇到了一个问题 来自服务器的Json响应(服务器型号): Json存储中使用的模型: Ext.regModel( 'mycabinet', { fields: [ { name : 'DeviceId', type: 'int' }, 'CabinetName'] }); json读取器代码: var iccDeviceReader = new Ext.data.JsonReader
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,但没有成功(名称:'DeviceId',映射:'id',convert:function(v){return v.id;})
我们将非常感谢您的帮助。
谢谢从阅读器中删除“字段”选项,并在模型配置中将“CabinetName”更改为{name:'CabinetName',映射:'firstname'}。
此外,idProperty也应该进入您的模型配置。以下代码解决了我的问题
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了
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
} );