我们在模型中存储了这样的字段:
fields: ["name_id", "name"]
我们有这样的列网格:
me.columns = [
{
header:"Name",
dataIndex:"name_id",
hide: true
},
{
header:"Name",
dataIndex:"name",
xtype: 'combocolumn',
editor: {
xtype:'NameCombo',
dataIndex:"name_id"
},
filter: true
},
]
其中xtype NameCombo定义为:
Ext.define("NameCombo",{
extend: "Ext.form.ComboBox",
triggerAction: 'all',
displayField: 'name',
valueField: 'id',
lazyRender: true,
editable: false,
store: "Store",
alias: ['widget.NameCombo'],
});
谁能告诉我,如何将ComboBox项'id'设置为我在配置中设置的另一列'nameInid:'name_id“'在NameCombo中?
答案 0 :(得分:0)
我有一个解决方案。
如果我们更改NameCombo小部件,如下所示,我们可以设置' id'到记录的另一个领域。
Ext.define("NameCombo",{
extend: "Ext.form.ComboBox",
displayField: 'name',
valueField: 'name',
keyField: 'id',
triggerAction: 'all',
lazyRender: true,
editable: false,
store: "Store",
alias: ['widget.NameCombo'],
initComponent: function(){
var me = this;
me.listeners = {
select: me.itemChanged
};
this.callParent();
},
itemChanged: function(combo, records, eOpts)
{
var me = this;
Ext.Array.each(records, function(record) {
if (me.dataIndex) {
var grid = me.scope;
var sm = grid.getSelectionModel();
var lastRow = sm.getLastSelected();
var columns = me.scope.columns,
i, columnsLength, column;
var id = record.data[me.keyField];
lastRow.set(me.dataIndex,id);
//TODO: Is there any simple way to update the value in the column of the grid?
for (i = 0, columnsLength = columns.length; i < columnsLength; i++) {
column = columns[i];
if (column.dataIndex === me.dataIndex) {
column.getEditor().setValue(id);
}
}
}
})
});
还有更好的解决方案吗?