【问题标题】:hasMany fields model display on extjs gridhasMany 字段模型显示在 extjs 网格上
【发布时间】:2021-06-17 04:20:42
【问题描述】:

我有 2 个 ExtJS 模型,称为 modelBase 和 modelChild。我已将“hasMany”modelChild 配置到 modelBase。

Ext.define('app.model.modelBase', {
    extend: 'Ext.data.Model',

    requires: [
        'Ext.data.field.String'
    ],
    uses: [
        'app.model.modelChild'
    ],

    fields: [{
        name: 'post_code'
    }, {
        name: 'building_name'
    }],

    hasMany: {
        associatedName: 'cabinet',
        model: 'app.model.modelChild',
        associationKey: 'cabinet'
    }
});

这是modelChild

Ext.define('app.model.modelChild', {
    extend: 'Ext.data.Model',

    requires: [
        'Ext.data.field.Field'
    ],

    belongsTo: 'app.model.modelBase',

    fields: [{
        name: 'operator'
    }]
});

我的问题是如何在 ExtJS 网格中显示 modelChild 字段(运算符)?我将有超过 1 条使用 modelChild 的记录。 我想在 ExtjS 网格的插件中使用“rowwidget”,但无法配置为显示运算符(来自 modelChild)

我目前正在使用 ExtJS 7.1

【问题讨论】:

  • 真正的问题是您希望这些值如何显示?听起来您可能想在网格中使用网格?如果是这样,您能否附上您正在尝试做的事情的小提琴,或者您正在尝试完成的事情的图片?

标签: extjs


【解决方案1】:

你必须使用渲染器来显示 hasOne 或 hasMany 关联

columns: [{
    dataIndex: 'notWorkingForHasOne',
    text: 'Type',
    flex: 1,
    // dataIndex is not working
    renderer: 'renderType'
}]

在视图控制器内部

// for hasOne userDetail
renderType: function (dataIndex, cell, record) {
    return record.getUserDetails().get('type');
},

// for hasMany publications
renderPublicationsFirstName: function (dataIndex, cell, record) {
    return record.publications().first().get('name');
},

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-04
    • 2017-01-12
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多