我希望有人可以指導我如何處理這個json數據結構。ExtJS 6 Rest代理其中JSON數據對象是ID
這裏有一個例子:(我有零控制這個數據的)
{
"1": {
"name": "thing 01",
"attributes": {
"color": "red",
"brand": "ACME"
}
},
"2": {
"name": "thing 02",
"attributes": {
"color": "blue",
"brand": "ACME"
}
}
}
所以我感到困惑如何使用reader
Ext.define('MyApp.model.Thing', {
extend: 'Ext.data.Model'
fields: [
{ name: 'name' },
{ name: 'attributes', type: 'auto' }
],
proxy: {
type: 'rest',
url: 'http://example.com/api/things',
reader: {
type: 'json',
rootProperty: ??? // <--- How should this work?
}
}
});
我已經得到了記錄想知道是否有辦法做類似...
rootProperty: '[id]'
還有一種方法來指定t他是什麼時候是數據對象的ID?也許不知何故在模型上使用idProperty
配置?
我應該使用reader.format方法嗎?這似乎有點毛...
任何想法是apreciated。謝謝!
「rootProperty」配置用於設置所有數據的根目錄,而不是每個記錄。另外,我還沒有在ExtJS 6 [documentation](http://docs.sencha.com/extjs/6.2.0/)中找到'reader.format'方法。 – MarthyM