Tro*_*dol 0 api rest json extjs extjs6
我希望有人可以指导我如何处理这个json数据结构.
这是一个例子:(我无法控制这些数据)
{
"1": {
"name": "thing 01",
"attributes": {
"color": "red",
"brand": "ACME"
}
},
"2": {
"name": "thing 02",
"attributes": {
"color": "blue",
"brand": "ACME"
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我对如何使用它获取记录感到困惑 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?
}
}
});
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法做某事......
rootProperty: '[id]'
Run Code Online (Sandbox Code Playgroud)
还有一种方法可以在数据对象时指定ID吗?也许以某种方式使用idProperty
模型上的配置?
我应该使用reader.format方法吗?那看起来有点粗......
任何想法都是贬值的.谢谢!
编写自定义读者类:
Ext.define('MyReader', {
extend: 'Ext.data.reader.Json',
alias: 'reader.myreader',
config: {
transform: function (data) {
var ret = [],
key, o;
for (key in data) {
o = data[key];
o.id = key;
ret.push(o);
}
return ret;
}
}
});
Ext.define('Thing', {
extend: 'Ext.data.Model',
fields: ['name', 'attribute'],
proxy: {
type: 'ajax',
url: 'data1.json',
reader: {
type: 'myreader'
}
}
});
Run Code Online (Sandbox Code Playgroud)
示例小提琴.
归档时间: |
|
查看次数: |
624 次 |
最近记录: |