gpt4 book ai didi

Extjs 5 数据模型 - 有很多关联

转载 作者:行者123 更新时间:2023-12-04 15:57:30 26 4
gpt4 key购买 nike

我正在尝试了解 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 和 categoryName 的对象)

出于某种原因,当我尝试获取用户的类别时,商店是空的。
userRecord.categories(); // has no records

我怎样才能让它工作?

最佳答案

请尝试一下

//用户

Ext.define('User', {
extend: 'app.data.Model',
fields: [
{name: 'id', type: 'string'},
{name: 'name', type: 'string'},
],
hasMany: {
Categories: {
type: 'Categories',
role: 'categories',
field: 'categories',
right: true
}
}
});

关于Extjs 5 数据模型 - 有很多关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26607119/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com