Huu*_*uze 7 javascript extjs handler
我正在使用ExtJS框架,我有以下处理程序,它只用作按钮的处理程序:
var myButtonHandler = function(button, event){
//code goes here
};
Run Code Online (Sandbox Code Playgroud)
我的按钮定义如下所示:
var myButton = new Ext.Button({
id : 'myButton',
renderTo : 'mybutton',
text : 'Save',
handler : myButtonHandler,
scope : this
});
Run Code Online (Sandbox Code Playgroud)
如您所见,处理程序接收预期的"按钮"和"事件".但是,我想将一些额外的信息传递给我的处理程序.我该怎么办?
我实际上会使用Exts createDelegate原型.
var appendBooleanOrInsertionIndex = 0; // Inserts the variables into the front of the function.
appendBooleanOrInsertionIndex = true; // Appends the variables to the end of the arguments
var myButton = new Ext.Button({
id : 'myButton',
renderTo : 'mybutton',
text : 'Save',
handler : myButtonHandler.createDelegate(this, [param1, param2], appendBooleanOrInsertionIndex),
scope : this
});
Run Code Online (Sandbox Code Playgroud)
在Ext JS 4中:
Ext.bind(myButtonHandler, this, [params array], true);
Run Code Online (Sandbox Code Playgroud)
你可以像布拉德利建议的那样使用一个好的解决方案.这是一个例子.其中repeatsStore - 它是我想要传递给按钮处理程序的附加参数.
Ext.create('Ext.panel.Panel', {
name: 'panelBtn',
layout: 'hbox',
border: 0,
items:[
{xtype: 'button', text: 'Add', name:'addBtn',
handler : Ext.bind(this.addBtnHandler, this, repeatsStore, true)
}
]
});
Run Code Online (Sandbox Code Playgroud)
你的处理程序应该有三个参数 - 前两个是标准的,最后一个是你的.
addBtnHandler:function(button, event, repeatsStore)
{
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27805 次 |
| 最近记录: |