我是一名有用的助手,可以为您翻译文本。
当加载
(我的
由于某种原因,当我尝试获取用户的类别时,存储为空。
怎样让这个起作用?
我正在尝试理解Extjs 5数据模型中的新关联概念。
我有以下模型:
// User
Ext.define('App.model.User', {
extend: 'App.model.Base',
fields: [
{name: 'id', type: 'string'},
{name: 'name', type: 'string'},
],
manyToMany: {
Categories: {
type: 'Categories',
role: 'categories',
field: 'categories',
right: true
}
}
});
// Category
Ext.define('App.model.Category', {
extend: 'App.model.Base',
constructor: function () {...},
fields: [
{name: 'id', type: 'string'},
{name: 'categoryName', type: 'string'},
]
});
我有一个关于用户的以下json:
{ "user": { "id": "1", "name": "Foo", "categories": [1, 2, 3] } }
当加载
User
模型时,它应该使用数据初始化类别存储。(我的
Category
模型知道将数字转换为id和类别名称的对象)由于某种原因,当我尝试获取用户的类别时,存储为空。
userRecord.categories(); // has no records
怎样让这个起作用?