Backbone.history.navigate('report',{trigger: true, replace: true});
你不應該使用這種渲染/不建議重裝應用程序views.This。
相反,你應該有一個控制器對象(JS對象)延伸Backbone.Events
定義一個回調的的路線「/報告」如下:
var MyAppBus = _.extend({},Backbone.Events);
MyAppBus.on("report",function(payLoad){
// 1.Load the data
// 2.Create an instance of the view passing the loaded data.
// (In your case, you could also pass an instance of the view in the payload
// and update the data alone in the view instance.)
// 3.Render the view.
// 4.Call the router navigate function with trigger set to false to
// update the url on a need basis.
});
現在,在event/router callback
你可以做這樣的事情:
MyAppBus.trigger("report",payLoad);
當有效載荷在事件回調可能是:
var payLoad = {};
payLoad.view = viewInstance;
有一個簡單的檢查 - 「if(this.fragment === fragment)return;'。也許你需要開展一些活動並在另一個地方抓住它,然後只是做你想做的事情? –
我會在你點擊的按鈕上重新渲染頁面的按鈕。就像Vahan所說的那樣,Backbone在散列片段相同時不會觸發事件。 –
如果您必須...您可以做到這一點 window.onhashchange = function(){ }; –