我在表单上的视图文件中设置的字段中有以下 2 个组件。
Ext.define('App.view.prospects.Filter', {
alias: 'widget.prospectsfilter',
extend: 'Ext.form.Panel',
itemId: 'prospectsfilter',
...
initComponent: function(){
...
this.testButton = Ext.create('Ext.button.Button', {
handler: function() {this.fireEvent('testEvent')},
iconCls: 'icon-apply_16x16',
itemId: 'testButton',
text: 'Test'
});
this.campaignsComboBox = Ext.create('Ext.form.field.ComboBox', {
anchor: '100%',
displayField: 'name',
fieldLabel: 'Campaign(s)',
itemId: 'campaignsComboBox',
labelWidth: 90,
listConfig: {
minWidth: 150
},
listeners: {
select: function() {this.fireEvent('testEvent');}
},
multiSelect: false,
queryMode: 'local',
store: this.campaignsStore,
value: null,
valueField: 'id'
});
现在,在控制器中,我有:
Ext.define('App.controller.ProspectsFilter', {
extend: 'Ext.app.Controller',
models: ['Prospect'],
stores: ['Prospects'],
views: ['prospects.Filter'],
...
init: function() {
this.control({
'prospectsfilter #testButton':{
testEvent: function(){console.log('Found #testButton!');}
},
'prospectsfilter #campaignsComboBox':{
testEvent: function(){console.log('Found #campaignsComboBox!');}
}
}
});
当我单击“testButton”时,我会在控制台中看到找到它的消息。
但是,当我在 中进行选择时campaignsComboBox
,什么也没有发生。
为什么?
更新:
以下是一个很好的测试,但未能确定根本原因。我添加了其他组件进行测试,文本字段的事件被很好地捕获。其他人失败。为什么?
这是更新的控制器:
Ext.define('MyApp.controller.ProspectsFilter', {
extend: 'Ext.app.Controller',
models: ['Prospect'],
stores: ['Prospects'],
views: ['prospects.Filter'],
init: function() {
this.control({
'prospectsfilter #campaignsComboBox' : {
render: this.comboRender,
select: this.comboSelect
},
'prospectsfilter #campaignsDateField' : {
render: this.dateRender,
select: this.dateSelect
},
'prospectsfilter #campaignsTextField' : {
render: this.textRender,
change: this.textChange
}
});
},
comboRender: function(combobox) {console.log('comboRender');}, // Never executes.
comboSelect: function(combobox) {console.log('comboSelect');}, // Never executes.
dateRender: function(dateField) {console.log('dateRender'); }, // Never executes.
dateSelect: function(dateField) {console.log('dateSelect'); }, // Never executes.
textRender: function(textField) {console.log('textRender'); }, // Executes.
textChange: function(textField) {console.log('textChange'); } // Executes.
});
这是更新的视图:
Ext.define('MyApp.view.prospects.Filter', {
alias: 'widget.prospectsfilter',
extend: 'Ext.form.Panel',
itemId: 'prospectsfilter',
....
initComponent: function(){
....
this.dateField = Ext.create('Ext.form.field.Date',{
fieldLabel: 'Date',
itemId: 'campaignsDateField'
});
this.textField = Ext.create('Ext.form.field.Text',{
fieldLabel: 'Text',
itemId: 'campaignsTextField'
});
this.campaignsComboBox = Ext.create('Ext.form.field.ComboBox', {
anchor: '100%',
displayField: 'name',
fieldLabel: 'Campaign(s)',
itemId: 'campaignsComboBox',
labelWidth: 90,
listConfig: {
minWidth: 150
},
multiSelect: false,
queryMode: 'local',
store: Ext.create('Ext.data.ArrayStore', {
fields: ['name'],
data: [['entry1'], ['entry2'], ['entry3']]
}),
tabindex: 7,
value: null,
valueField: 'id'
});
this.statusToSegmentFieldSet = Ext.create('Ext.form.FieldSet', {
anchor: '100%',
autoHeight: true,
collapsed: true,
collapsible: true,
defaults: {
editable: false,
forceSelection: false
},
items: [
this.dateField,
this.textField,
this.campaignsComboBox
],
layout: 'anchor',
margin: '10 10 10 10',
title: 'Dispositions, Campaigns, Segments'
});
.......
var config = {
autoRender: true,
autoScroll: true,
bodyStyle: 'background-color: #F1F1F1;',
border: true,
//buttons: [
// this.applyButton,
// this.clearButton
//],
collapsed: false,
collapsible: true,
frame: true,
height: 200,
items: [
//this.datePicker,
//this.dateRangeFieldSet,
//this.prospectDetailsFieldSet,
this.statusToSegmentFieldSet
//this.assignedToFieldSet
],
layout: 'anchor',
minWidth: 300,
region: 'east',
split: true,
stateId: 'prospectsModuleFilter',
title: 'Advanced Filters',
width: 300
};
Ext.apply(this, Ext.apply(this.initialConfig, config));
this.callParent(arguments);
}
});
更新:8月28日:
好的。我进一步缩小了范围,以至于我可以重现我们在 JSFiddle 中遇到的问题。
希望这将使某人很容易帮助我找出问题所在。
请在此处阅读 JSFiddle 的注释:http: //jsfiddle.net/4JubT/3/