您可以通过在导航控制器中跟踪所有菜单项和子菜单项(这些或多或少是您的路线)以编程方式处理此问题。导航模板显示所有菜单项和活动菜单项的子菜单项。单击菜单项会更改活动的菜单项,单击子菜单项会触发一个navigateTo
动作,您可以在其中执行逻辑来处理转换。
导航控制器:
navigationItems: ["spots, rankings"]
subNavigationItems: {
spots: [ "aroundYou" , "search" ]
rankings: ["topUsers", "topSpots"]
}
// `newItem` is the navigation menu item the user clicked on
selectNavigationItem: function(newItem) {
this.set('currentNavigationItem', newItem);
}
// `target` is a string from subNavigationItems that gets passed through the action helper when the user clicks on a submenu item
navigateTo: function(target) {
// construct the route from the active navigation item and the chosen subitem
route = this.get('currentNavigationItem') + "." + target
this.transitionToRoute(route)
}
currentNavigationItem: null // or whatever default
// change the subnavigation items to display based on the current navigation path
currentSubNavigationItems: function() {
key = this.get('currentNavigationItem')
return this.get('subitems')[key]
}.property('currentNavigationItem')
导航.hbs:
<div class="navigation">
{{#each navigationItem in navigationItems}}
<a {{action selectNavigationItem navigationItem}}> {{navigationItem}} </a>
{{/each}}
</div>
<div class="subnavigation">
{{#each subNavigationItem in currentSubNavigationItems}}
<a {{action subNavigateTo subNavigationItem}}> {{subNavigationItem}} </a>
{{/each}}
</div>
如果不清楚,请告诉我。