2014-02-26 32 views
0

嗨extjs專家我有一個簡單的問題,但無法找到正確的方法來做到這一點,並在Google上搜索了幾天。我在extjs元素的配置文件中有一個監聽器,用這種方法很容易,但是我怎樣才能將監聽器從配置文件中取出,並將它放在配置文件之外,因此配置將盡可能最少,並且一個監聽器可以可多次使用只是實現的功能調用, 這裏是我的代碼:Extjs聆聽者出的配置

Ext.define("my.filter.TimeFilter",{ 
extend: "Ext.tab.Panel", 
alias: "widget.myTimeFilter", 
requires: ["my.filter.Filters"], 
config: { 
    cls: 'ruban-filter-timefilter', 
    items: [ 
      { 
       title: 'Time sections', 
       xtype: 'radiogroup', 
       fieldLabel: 'Time Selector', 
       items: [ 
        { 
         boxLabel: '60 Mins', 
         name: 'unixMills', 
         inputValue: '3600000' 
        }, { 
         boxLabel: '8 Hours', 
         name: 'unixMills', 
         inputValue: '28800000' 
        }, { 
         boxLabel: '24 Hours', 
         name: 'unixMills', 
         inputValue: '86400000' 
        }, { 
         boxLabel: '7 Days', 
         name: 'unixMills', 
         inputValue: '604800000' 
        }, { 
         boxLabel: '30 Days', 
         name: 'unixMills', 
         inputValue: '2592000000' 
        } 
        ], 
        listeners: { 
         change: function (field, newValue, oldValue) { 
          var endTime = new Date().getTime(); 
          var startTime = endTime - newValue['unixMills']; 
          console.log("StartTime: " + startTime); 
          console.log("EndTime: " + endTime); 

         } 


      } 
     ] 
    }, 

constructor: function(config){ 
    this.callParent(arguments); 
} 

});

,所以我相信構造爲單獨的功能或監聽器本身後它應該去,但我不知道,沒那麼好熟悉js和ExtJS的, 感謝大家

回答

0

您可以添加配置之外的聽衆這種方式:

myElement.on('change', function() { ... }