Jos*_*mit 3 javascript extjs extjs4 extjs-mvc extjs4.1
我有以下ExtJS控制器代码:
init: function() {
this.control({
'#menuitem-A': { click: this.handlerA },
'#menuitem-B': { click: this.handlerB },
});
},
Run Code Online (Sandbox Code Playgroud)
和以下事件处理程序:
commonFunc: function(param1, param2) {
// do something with param1 and param2 in here
},
handlerA: function(button, event) {
this.commonFunc('param-A1', 'param-A2');
},
handlerB: function(button, event) {
this.commonFunc('param-B1', 'param-B2');
},
Run Code Online (Sandbox Code Playgroud)
问题:当前的代码是多余的:handlerA和handlerB只需要调用commonFunc不同的参数
问题:对于不同的事件处理程序,
我想删除handlerA和handlerB替换call或使用上面的函数和上面的apply函数中的常用函数.可能吗?commonFunchandlerAhandlerB
例:
init: function() {
this.control({
'#menuitem-A': { click: /*commonFunc with ['param-A1', 'param-A2']*/ },
'#menuitem-B': { click: /*commonFunc with ['param-B1', 'param-B2']*/ },
});
},
Run Code Online (Sandbox Code Playgroud)
非常感谢!
这个怎么样:
init: function() {
this.control({
'#menuitem-A': {
click: function(button, event){
this.commonFunc('param-A1', 'param-A2');
}
},
'#menuitem-B': {
click: function(button, event){
this.commonFunc('param-B1', 'param-B2');
}
}
});
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
926 次 |
| 最近记录: |