问题描述
我有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');
},