2011-06-14 68 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);