我在使用Ext.data.JsonReader映射Ext.data.JsonStore模型時遇到了sencha中的問題。無法在Sencha Touch中使用JsonReader映射JsonStore中的模型
從服務器(服務器模型)JSON響應:以JSON商店使用
{"rows":[{"id":1,"firstname":"Bill"},{"id": 2,"firstname":"Ben"}]}
型號:
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」模型會被填充「服務器模型」。但是,映射不會發生。 我甚至嘗試使用轉換沒有任何成功(名稱:'DeviceId',映射:'ID',轉換:函數(v){返回v.id;})
任何幫助將不勝感激。 感謝
非常感謝...在模型中做映射而不是jsonReader解決了我的問題... – nuzahat