首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Extjs 5数据模型-有许多关联

Extjs 5数据模型-有许多关联
EN

Stack Overflow用户
提问于 2014-10-28 19:24:39
回答 1查看 1.2K关注 0票数 6

我正在尝试理解Extjs5数据模型中的新关联概念。

我有以下模型

代码语言:javascript
复制
// 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:

代码语言:javascript
复制
 { "user": { "id": "1", "name": "Foo", "categories": [1, 2, 3] } }

当加载User模型时,它应该用数据初始化类别存储。

(我的Category模型知道将数字转换为id &categoryName的对象)

由于某些原因,当我尝试获取用户的类别时,商店是空的。

代码语言:javascript
复制
userRecord.categories(); // has no records

我怎么才能让它工作呢?

EN

回答 1

Stack Overflow用户

发布于 2014-11-06 21:40:24

请试试看

//用户

代码语言:javascript
复制
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
        }
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26607119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档