我在使用自定义模板和点击监听器禁用按钮时遇到问题。这是按钮代码:
items: [
{
autoEl: {
tag: 'div'
},
cls: 'btn-save uiBtn blue',
html: '<label><input type="button" value="SAVE"></label>',
xtype: 'button',
listeners:{
'click': {
element: 'el',
fn: function(){
this.submitForm();
}
},
scope:this
}
},
不幸的是在click事件处理函数中没有。 disable()
,dom.disabled = 'true'
不起作用。如何禁用这种按钮?
答案 0 :(得分:1)
您已经更改了侦听器的范围,因此这指向了除按钮之外的其他内容。你应该使用handler参数:
'click': {
element: 'el',
fn: function(e, sender){
sender.disabled = true;
this.submitForm();
}
},
答案 1 :(得分:0)
事实证明,为侦听器功能定义'this'并不是最好的主意。相反,我将其保存为按钮的本地属性中的引用,并在“命中”操作按钮本身。
that: this,
listeners:{
'click': function(){
this.disable();
this.that.submitForm();
}