PDA

View Full Version : Multiple Ext.Button handlers



DavorZ
9 Mar 2011, 5:37 AM
is there a way to put multiple handlers on a button, so it starts multiple functions at once?? :-/
something like, open all button??



Ext.onReady(function() {

var myButtonAll = new Ext.Button({

text : "OPEN ALL",
handler : varname, varname...???
renderTo : "buttons",
scale : "large",
iconCls : "button_two",
width : 100,
height : 100,


});


});

johnathanhebert
9 Mar 2011, 6:25 AM
Since the "handler" config option just assigns the function to the click event of the button... you can add multiple click events to your button like this:


Ext.onReady(function() {
var myButtonAll = new Ext.Button({
text : "OPEN ALL",
handler : varname, varname...???
renderTo : "buttons",
scale : "large",
iconCls : "button_two",
width : 100,
height : 100,
});
myButtonAll.on('click', handler1);
myButtonAll.on('click', handler2);
myButtonAll.on('click', handler3);
myButtonAll.on('click', handler4);
});Or you can wrap all of them in an anonymous function like this:


Ext.onReady(function() {
var myButtonAll = new Ext.Button({
text : "OPEN ALL",
handler : function() {
handler1.apply(this, arguments);
handler2.apply(this, arguments);
handler3.apply(this, arguments);
handler4.apply(this, arguments);
}
renderTo : "buttons",
scale : "large",
iconCls : "button_two",
width : 100,
height : 100,
});
});

And the handlers should have the signature of the button click handler, for example:


handler1 = function(button, event) {...}

mitchellsimoens
9 Mar 2011, 6:54 AM
You don't need to be an anonymous function. Adding multiple event listeners will affect performance. Best way to do it is have a wrapping function.

DavorZ
10 Mar 2011, 1:52 AM
thank you very much, i did the wrapping , it works!!! :D