2011-06-14 66 views
0

我遇到問題,正在使用下面的應用程序進行一些範圍確定。在我調用this.fireEvent時,我不再限制在我的應用程序中,而是在文檔窗口中。PhoneGap和Sencha touch的範圍問題

任何想法?

DN.App = Ext.extend(Ext.Panel, { 
    initComponent: function() {  
     document.addEventListener("backbutton", this.backKey, true); 
     DN.App.superclass.initComponent.call(this);  
    }, 

    setActivePanel: function(){ 
     //global handler for switching panels 
    }, 

    backKey: function(){ 
     var prev = DN.App.prevPanel[DN.App.prevPanel.length-1]; 
     DN.App.prevPanel.pop(); 

     //This handles the switching of panels, but 'this' is scoped to html document at this point 
     this.fireEvent('setActivePanel',prev); 
    } 
});

找到答案 呸,我曾在此一對夫婦小時發佈,然後算出它輸出8分鐘後前。我嘗試使用DN.App.fireEvent但這也沒有奏效。然後我意識到DN.App只是我製作的課程,而不是實際的對象。在另一個文件中,我將其稱爲DNApp = new DN.App();在看到我試過DNApp.fireEvent後,它工作得很好。

回答

1

問題是「document.addEventListener(」backbutton「,this.backKey,true);」,當事件被觸發時,預期將「this」關鍵字綁定到激發它的對象,你可以實現你想要什麼樣的封閉,如:

document.addEventListener("backbutton", (function(self){ return function(){ self.backKey(); }; })(this), true);