hasMany字段模型显示在extjs网格上

问题描述

我有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',requires: [
        'Ext.data.field.Field'
    ],belongsTo: 'app.model.modelBase',fields: [{
        name: 'operator'
    }]
});

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

我当前正在使用ExtJS 7.1

解决方法

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

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

并在viewController内部

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...