Backbone.Router
在执行路由之前和之后是否存在事件?我的应用程序jQuery.mobile
在执行路由之前需要使用并调用 $.mobile.changePage,并且在控制器中可以通过 $.activePage 访问当前显示的页面。控制器操作完成后,我应该触发create
文档上的事件以通过 $.mobile 新创建的元素来“增强”。我通过替换来做到这一点loadUrl
Backbone.history.loadUrl = ( function( old ){
return function() {
Router.trigger("all:before");
old.apply( Backbone.history, arguments );
Router.trigger("all:after" );
}
})( Backbone.history.loadUrl );
//Router.initialize
initialize: function() {
this.bind( "all:before", function( ) {
$.mobile.changePage( window.location.hash.split( "/" )[0] || "home", { changeHash:false} );
});
this.bind( "all:after", function() {
$.mobile.activePage.trigger('create');
});
}
可能有一些像这样的内置事件吗?