EasyUI Forum
May 14, 2024, 01:59:50 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: appending multiple functions to events  (Read 7274 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: May 10, 2013, 03:33:53 AM »

How can I append multiple functions to an event, such that they are appended to and don't overwrite the previous function.

Code:
cbo.combobox('options').onSelect = function(){ functionA();};

if( x==y) cbo.combobox('options').onSelect += function(){ functionB();};
Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 10, 2013, 07:35:15 AM »

Here is the simple solution to achieve this functionality.
Code:
	function CB(){
this.ff = [];
this.onSelect = (function(){
var ff = this.ff;
return function(row){
for(var i=0; i<ff.length; i++){
ff[i].call(this,row);
}
}
}).call(this);
};
CB.prototype.add = function(f){
this.ff.push(f);
};
var cb = new CB();
cb.add(function(row){
console.log('function1:'+row);
});
cb.add(function(row){
console.log('function2:'+row);
});
Code:
	cbo.combobox('options').onSelect = cb.onSelect;
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!