2011-03-04 103 views
3

是否可以在調用之後從一個Ext.Panel中刪除監聽器? 我有一個tap-Listener,我想在第一次調用後刪除它。我嘗試了很多方法來刪除聽衆,但它仍然呼籲:從面板中刪除監聽器

registerListeners: function() 
{ 
    // this = Ext.Controller 
    // this.view = Ext.Panel 
    this.view.on('tap', this.onTap, this, {element: 'body'}); 
}, 

unregisterListeners: function(evt, el, o) 
{ 
    console.log("Removing Event..."); 
    this.view.el.un('tap', this.onTap, this); // Don't work, on the next tap its still calling 
}, 

onTap: function(evt, el, o) 
{ 
    Ext.ControllerManager.get('mycontroller').unregisterListeners(); 
} 

我真的很困惑?!? :(任何建議?

+0

爲的addListener的文檔你有沒有注意到你正在設置監聽器在this.view上,但是在this.view.el上取消設置它是故意的嗎? – ChrisR 2011-03-04 19:26:07

+0

哦,這是錯誤的,我必須用this.view.getEl()。on和this.panel.getEl()重新測試它。removeListener – Tariq 2011-03-07 13:11:16

回答

4

是的,你可以在上/的addListener調用設置的一個選項。

myButton.on('click', function(){ 
    /* do stuff */ 
}, this, { single : true }); 

// In your case: 
this.view.on('tap', this.onTap, this, {element: 'body', single: true}); 

檢查http://dev.sencha.com/deploy/touch/docs/?class=Ext.Component

+0

哦,你說得對,但它仍然在打電話?!?這真的很奇怪...也許是一個錯誤?你測試過嗎? – Tariq 2011-03-04 15:16:39

+0

我已經使用了罪惡gle:真正的選擇好幾次是的,但我不知道你的應用還涉及到什麼,它是否公開在我們可以檢查的地方? – ChrisR 2011-03-04 15:34:20

+0

我已經在一個單獨的項目中測試過它,它工作。也許這是一個與sencha衝突的其他組件或lib。 Thx再次:) – Tariq 2011-03-07 13:08:50