【问题标题】:Ext JS Models : One-to-one AssociationsExt JS 模型:一对一的关联
【发布时间】:2012-10-17 06:07:35
【问题描述】:

建立一对一关系的最佳方式是什么?这是我想要的:

Ext.define('MyApp.model.Post', {
    extend : 'Ext.data.Model',
    fields : [ 'id', {
        name : 'author',
        type : 'MyApp.model.Author'
    }, {
        name : 'content',
        type : 'string'
    } ],
    hasMany : {
        model : 'MyApp.model.Comment',
        name : 'comments'
    }
});

据我所知,author 将被视为对象文字属性而不是 Ext JS 模型,这意味着它不能用作记录。另外,getAuthor() 不可用。

另一种选择是:

Ext.define('MyApp.model.Post', {
    extend : 'Ext.data.Model',
    fields : [ 'id', 'authorID', {
        name : 'content',
        type : 'string'
    } ],
    hasMany : {
        model : 'MyApp.model.Comment',
        name : 'comments'
    }
});

现在获取作者信息需要在某个地方进行另一个加载调用。

哪种做法最好,两者的优缺点是什么?使用第一个版本并存储重要信息(如作者姓名)并仅在将用作记录时才对完整作者对象进行进一步加载调用是否有利?

【问题讨论】:

    标签: extjs model


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多