我有一个描述问题的Sencha Fiddle: https://fiddle.sencha.com/#fiddle/13ol
我想初始化组合,但是要避免触发它的更改事件(直到init()完成之后)。 combo的值首先在viewController init()方法中可用。
答案 0 :(得分:0)
使用value
配置创建具有初始值的组合框。
Ext.define('MyApp.view.TestViewControler', {
...
init: function() {
// Do something
var newValue = 'Week'; // Get new value
this.getView().addCombo(newValue);
}
...
});
Ext.define('MyApp.view.TestView', {
...
addCombo: function(value) {
this.add({
xtype: 'combo',
reference: 'MyCombo',
editable: false,
hidden: false,
fieldLabel: 'My Combo',
bind: {
store: '{comboStore}'
},
displayField: 'name',
valueField: 'key',
listeners: {
change: 'onMyComboChange'
},
value: value
});
}
});
答案 1 :(得分:0)
我不知道如何将它推迟到init函数之后,但你至少可以推迟到init函数结束之前:
init: function() {
var combo = this.lookupReference('MyCombo');
combo.suspendEvent("change");
combo.setValue('Week');
// do everything else you want to do in init.
combo.resumeEvent("change");
}
我已经在你的小提琴中测试了这段代码:
init: function() {
var combo = this.lookupReference('MyCombo');
combo.suspendEvent("change");
combo.setValue('Week');
console.log('testfirst');
combo.resumeEvent("change");
},
onMyComboChange: function() {
console.log('testsecond')
// Need to avoid firing this method during init
}
生成此console.log:
run?_dc=1452632485198:60 testfirst
run?_dc=1452632485198:65 testsecond