2011-10-05 77 views
0

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

任何幫助將不勝感激。 感謝

回答

0

從您的閱讀器「域」選項,並更改「CabinetName」{名稱:「CabinetName」,映射:「姓」}在模型的配置。 另外,idProperty也應該進入你的模型配置。

+0

非常感謝...在模型中做映射而不是jsonReader解決了我的問題... – nuzahat

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了。

相關問題