当用户向后和向前单击时,我想调用我的控制器。但我无法在 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 Exception 25
那么,如何在 window.onpopstate 中访问我的控制器?或者是否可以在我的控制器中为向后和向前事件添加侦听器?