我試圖找出以下情形:Backbone.js:嵌套視圖的路由
可以說我有兩個視圖:一個用於查看項目,另一個用於購買它們。問題在於購買視圖是用於查看的子視圖。
對於路由我有:
var MyRouter = Backbone.Router.extend({
routes: {
'item/:id': 'viewRoute',
'item/:id/buy': 'buyRoute'
}
});
var router = new MyRouter;
router.on("route:viewRoute", function() {
// initialize main view
App.mainview = new ViewItemView();
});
router.on("route:buyRoute", function() {
// initialize sub view
App.subview = new BuyItemView();
});
現在,如果用戶刷新頁面,並buyRoute
被觸發,但現在沒有主視圖。什麼是解決這個問題的最佳解決方案?
中的CoffeeScript上面的代碼,如果你喜歡:https://gist.github.com/4597528 – georgedyer