2012-11-02 42 views
0

「我有一個基地CLASSE,其中定義了兩個聽衆:祖先事件不叫

Ext.define('App.controls.CoWindow', { 
extend: 'Ext.window.Window', 
listeners: { 
    show: { 
     fn: function(win, opt){ 
      alert('opened from base class'); 
     }, 
     scope: this 
    }, 
    close: { 
     fn: function() { 
      alert('closed from base class'); 
     } 
    } 
} 
}) 

如果我宣佈延長這一新的類,並且配置偵聽,祖先事件不叫:

var procura = Ext.create('App.controls.CoWindowEx', { 
      listeners: { 
       close: { 
        fn:function() { 
         alert('closed from extending class'); 
        } 
       } 
      } 
     }); 

當我需要這兩條消息時,我只得到「從擴展類關閉」。

回答

0

因爲您正在覆蓋超類原型上的偵聽器配置。如果你必須那樣做:

Ext.define('App.controls.CoWindow', { 
    extend: 'Ext.window.Window', 

    initComponent: function(){ 
     this.callParent(); 
     this.on('show', function(){ 
      console.log('super show'); 
     }); 
     this.on('close', function(){ 
      console.log('super close'); 
     }); 
    } 
}); 
+0

你能告訴我什麼時候使用「監聽」,什麼時候不使用? – Beetlejuice

+0

他們實現同樣的事情,問題是你只是覆蓋了價值。如果您打算在創建實例時傳遞偵聽器,則不要將偵聽器放在類定義上。 –