3
我对ExtJS相当陌生,并且正在为此付出一点努力。如何创建一个具有多个属于同一模型类型的ExtJS 4模型?
我有一个“人”模型,它与同一模型(母亲和父亲)有一对关系。
虽然我不清楚如何访问这些关系。下面是我得到了什么:
Ext.define('IwiDb.model.Person', {
extend: 'Ext.data.Model',
fields: [
'ID',
'Title',
'FirstName',
'MiddleNames',
'Surname',
//.. snip
'MotherID',
'FatherID',
],
associations: [{
type: 'belongsTo',
model: 'IwiDb.model.Person',
primaryKey: 'ID',
foreignKey: 'MotherID',
autoLoad: true,
name: 'Mother',
getterName: 'getMother',
},{
type: 'belongsTo',
model: 'IwiDb.model.Person',
primaryKey: 'ID',
foreignKey: 'FatherID',
autoLoad: true,
name: 'Father',
getterName: 'getFather',
}],
idProperty: 'ID',
proxy: {
type: 'rest',
url: 'api/v1.extjs/Person',
format: 'json',
reader: {
type: 'json',
root: 'items',
totalProperty: 'totalSize',
},
writer: {
type: 'json',
},
simpleSortMode: true,
}
});
编辑:我觉得我越来越近,我已经更新了代码,我现在得到。至少现在我可以做person.getMother()并返回一个函数。但我仍然无法获取数据。任何人都知道吗?