ユーザーが前後にクリックしたときにコントローラーを呼び出したい。しかし、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 のエラー: Uncaught Error: DATA_CLONE_ERR: DOM Exception 25
次に、 window.onpopstate でコントローラーにアクセスするにはどうすればよいですか? または、コントローラーの前後のイベントにリスナーを追加することは可能ですか?