Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs: how can I add event handlers to a component in its raw object form (xtype)

I have an extjs component in its raw object type, for example:

var x = {
   xtype: 'button', 
   text: 'Delete', 
   handler: whatever, 
   more:config, 
   more2: config2};

Now I want to add some listener to x. In my scenario I don't have access to the x object before or right after it is created. I just want to add an event handler when it is just a javascript object without overwriting existing handlers. How can that be done?

like image 601
flybywire Avatar asked Jan 27 '26 21:01

flybywire


2 Answers

You can use the listeners config to do this

{
   xtype: 'button', 
   text: 'Delete', 
   handler: whatever, 
   more:config, 
   more2: config2,
   listeners:{
      scope : this,
      event1 : function(){},
      event2 : function(){}
   }

};

like image 71
Arun P Johny Avatar answered Jan 29 '26 09:01

Arun P Johny


A listeners config is needed:

var x = {
   xtype: 'button', 
   text: 'Delete', 
   handler: whatever, 
   more:config, 
   more2: config2,
   listeners: {
     click: function() {
       ...       
     },
     render: function() {
       ...
     }
   }
};
like image 45
alex.zherdev Avatar answered Jan 29 '26 10:01

alex.zherdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!