2013-04-10 21 views
1

我試圖添加和使用on()un()函數(的addListenerremoveListener別名)除去在運行時監聽器。Ext.mixin.Observable.on()/ .UN():函數引用不匹配

UN(eventName的,FN,[範圍],[選項],[: 我從與煎茶的getCmp()

Ext.Viewport.on('orientationchange', Ext.getCmp('foo').handleOrientationChange, foo, {buffer: 50}); 
Ext.Viewport.un('orientationchange', Ext.getCmp('foo').handleOrientationChange); 

從煎茶文檔檢索的組件的一個實例採取函數參照order])

要移除的處理程序。這必須是對通過addListener調用傳遞 的函數的引用。

我不清楚爲什麼這不起作用。很明顯,第二個函數引用不匹配第一個,但爲什麼會發生這種情況?不應該Ext.getCmp('foo')返回相同的對象?

+0

' getCmp'應該返回相同的實例。你確定問題不在其他地方嗎?如果你做'iHandler = Ext.getCmp('foo')。handleOrientationChange'並且給''on'和'un'同時給'iHandler'呢? – Izhaki 2013-04-10 21:45:29

回答

1

當調用removeListener您還需要爲addListener那麼只有聽者將被刪除指定的傳遞同一範圍

Ext.Viewport.un('orientationchange', Ext.getCmp('foo').handleOrientationChange, foo); 

scope : Object (optional) 
The scope originally specified for the handler. It must be the same as the scope argument specified in the original call to addListener or the listener will not be removed. 

檢查:

Sencha Docs