我想在用户单击后退和前进时调用我的 Controller 。但我无法在 window.onpopstate 中访问我的 Controller 。我还尝试将我的 Controller 放入历史状态数据中,但这会导致错误。
尝试在 onpopstate 中访问我的 Controller :
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(){...} });
尝试将我的 Controller 置于状态:
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 中的错误: Uncaught Error :DATA_CLONE_ERR:DOM 异常 25
那么,如何在 window.onpopstate 中访问我的 Controller ? 或者是否可以在我的 Controller 中添加向后和向前事件的监听器?
最佳答案
终于找到解决办法了!在我的 Controller 中编写以下代码:
window.onpopstate = Ext.bind(this.onPopState, this);
这可以将函数作用域更改为我的 Controller ,然后我可以在 onpopstate 中调用我的 Controller !
关于javascript - ExtJS:如何在window.onpopstate中调用 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12703240/