[英]ExtJS: How to call controllers in window.onpopstate?
當用戶向后和向前點擊時,我想調用我的控制器。 但是我無法在window.onpopstate中訪問我的控制器。 我還試圖將我的控制器放入歷史狀態數據,但它會導致錯誤。
嘗試在onpopstate中訪問我的控制器:
Ext.define('PageController',{ extend:'Ext.app.Controller', onLaunch:function(){ window.onpopstate = this.onPopState; //trigger the onPopState function when backward and forward window.history.pushState(null, '', '/'); }, onPopstate:function(s){ this.someFunction(); //"this" is not PageController, it's PopStateEvent }, someFunction:function(){...} });
嘗試將我的控制器置於狀態:
Ext.define('PageController',{ extend:'Ext.app.Controller', onLaunch:function(){ window.onpopstate = this.onPopState; //trigger the onPopState function when backward and forward window.history.pushState({'controller':this}, '', '/'); //try to put my controller into state data, which causes error }, onPopstate:function(s){ s.state.controller.someFunction(); }, someFunction:function(){...} });
firebug中的錯誤:未捕獲錯誤:DATA_CLONE_ERR:DOM異常25
然后,我如何在window.onpopstate中訪問我的控制器? 或者是否可以在我的控制器中向后向和前向事件添加偵聽器?
我終於找到了解決方案! 在我的控制器中寫下以下代碼:
window.onpopstate = Ext.bind(this.onPopState, this);
這可以將功能范圍更改為我的控制器,然后我可以在onpopstate中調用我的控制器!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.