在我的Ember应用程序中,我需要显示几个不同的菜单或nabbers,具体取决于用户所在应用程序的部分。建议的方法是什么?我试图做的是在我的模板中查看:
{{view App.NavbarView controllerBinding="App.CurrentNavbarController.nav"}}
在我看来,我正在检查路径:
App.NavbarView = Ember.View.extend({
templateName: function() {
path = App.getPath('router.currentState.path');
//change navbar
}
});
那就是我被困住的地方。如何动态切换视图?
答案 0 :(得分:0)
一种方法是使用路由器进行设置。
someRoute:
connectOutlets: (router, model)->
# ... normal stuff here
App.set 'section', 'theNameOfThisSection'
exit: (router)->
App.set 'section', ''
subRoute:
# ... in the sub route, App.section will still be set
答案 1 :(得分:0)
另一种方法是使用路由器将某些插座连接到导航视图。
在application.handlebars
放置指定的插座:
{{outlet nav}}
在路由器中,输入路线时连接插座:
userRoute:
connectOutlets: (router, model)->
# normal stuff here
router.get('applicationController').connectOutlet('navbar', 'userNav', model)
exit: (router)->
router.get('applicationController').disconnectOutlet 'navbar'
subRoute:
# still has the navbar outlet connected in a subroute