最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

I have an extjs ponent 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?

I have an extjs ponent 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?

Share Improve this question asked Mar 3, 2010 at 15:10 flybywireflybywire 274k200 gold badges405 silver badges509 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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(){}
   }

};

A listeners config is needed:

var x = {
   xtype: 'button', 
   text: 'Delete', 
   handler: whatever, 
   more:config, 
   more2: config2,
   listeners: {
     click: function() {
       ...       
     },
     render: function() {
       ...
     }
   }
};
发布评论

评论列表(0)

  1. 暂无评论