我很难从分机中得到我想要的东西。我正在尝试使用嵌套参数划分 RESTful 响应。其中一个参数是一个对象数组,其中每个对象还有几个参数。如何建立模型/商店/视图来识别这种类型的响应?
response = {
stuffINeed: {
animals,
fruits,
veggies = {
cucumbers,
apples,
pears,
squash = {
winter,
pumpkin,
summer = {
yellow,
green
}
}
}
},
stuffIDontNeed: {
...
},
moreStuffIDontNeed: {
...
}
}
如何使用关联来建立我的模型/商店?让我们假设“基本”模型如下所示:
Ext.define('MyApp.model.StuffINeed', {
extend: 'Ext.data.Model',
fields: [
{name: 'animals', type: 'boolean'},
{name: 'fruits', type: 'boolean'},
{name: 'veggies', type: 'array'}
],
hasMany: [{name: 'veggies', model: 'veggieModel'}],
proxy: {
type: 'REST',
url: '/someserver'
reader: {
root: 'data',
totalProperty: 'totalCount'
}
}
}
我是否需要第二个反映我正在寻找的参数的素食模型?如何将一系列素食模型注入我的根?
Ext.define('MyApp.model.Veggie', {
extend: 'Ext.data.Model',
fields: [
{name: 'cucumbers'},
{name: 'apples'},
{name: 'pears'},
{name: 'squash', type: 'array'}
belongsTo: 'MyApp.model.StuffINeed'
]
});