Javascript TypeError:combo.getSelection(…)在呈现事件中为空。Extjs 6
在Ext.window.window组件中,我使用combobox字段:Javascript TypeError:combo.getSelection(…)在呈现事件中为空。Extjs 6,javascript,extjs,Javascript,Extjs,在Ext.window.window组件中,我使用combobox字段: Ext.define('BookApp.view.BookEdit', { extend: 'Ext.window.Window', alias: 'widget.bookwindowedit', layout: 'fit', autoShow: true, store: 'BookStore', modal : true, initComponent: function() { var me = this
Ext.define('BookApp.view.BookEdit', {
extend: 'Ext.window.Window',
alias: 'widget.bookwindowedit',
layout: 'fit',
autoShow: true,
store: 'BookStore',
modal : true,
initComponent: function() {
var me = this;
me.myStates = Ext.data.StoreManager.get('States').load();
me.items = [{
xtype: 'form',
items: [
{
xtype: 'combobox',
fieldLabel: 'Статус',
name: 'status',
store: me.myStates,
valueField: 'name',
displayField: 'name',
typeAhead: true,
queryMode: 'remote',
listeners: {
'select': function (combo, records) {
index = records.internalId;
filterCombo(combo, index);
},
'boxready': function () {
console.log("form's boxready");
index = combo.getSelection().internalId;
filterCombo(combo, index);
}
}
},
]
}];
me.buttons = [{
text:'Save',
iconCls:'save-icon',
action: 'save'
},
{
text: 'Clear',
scope: this,
action: 'clear'
}
];
me.callParent(arguments);
}
});
function filterCombo(combobox, index) {
store = combobox.getStore();
store.clearFilter();
store.filterBy(
function(record) {
if ((record.data.order_install == index - 1) || (record.data.order_install == index + 1)) {
return true;
} else {
return false;
}
}
);
};
在呈现事件的侦听器中尝试获取索引项时,会发生错误:
TypeError:combo.getSelection(…)是nul
为什么会发生错误以及如何正确获取索引项?
添加boxready事件以获取记录时,此事件不起作用。当您使用“initComponent的定义时,请确保调用
“this.callParent()”
在“initComponent”定义的末尾。
在触发“渲染”事件时,不会有任何选择,因此将得到空数组。
通过类似“combo.setSelection(0)”的方式显式设置选择 是的,在“initComponent”的末尾有me.callParent(参数);在我的例子“render”中,如何正确地获取internalId以将其传递给filterCombo函数?我更正了我的问题,将事件从“render”更改为类似“boxready”的内容,然后您将获得“getSelection”的一些值,因为存在一些默认选择。此外,当“select”事件中已经存在筛选时,我认为没有必要在“render”事件中执行。将“render”更改为“boxread”,但它不起作用。在问题中更正了我的观点是它按预期工作,即它将返回null,因为在组合框的开头不会有任何选择。如果您希望在开头进行选择,则需要显式设置选择。