这个问题困扰了我好几天。当用户访问“关于”页面时,我需要在应用程序模板的主导航下显示一个子导航。我觉得我一定遗漏了一些重要的概念,因为我一直在阅读,如果在 Ember 中很难做某事,那么你可能做错了。而且我觉得 Ember 应该能够轻松处理简单的子导航。
当单击“关于”时,我希望子导航显示在主导航下方的瘦白色水平条上。
由于导航代码位于应用程序模板中,因此我无法将子导航放在 about 模板中。
我的路由器:
App.Router.map(function() {
this.resource("about", function() {
this.route("philosophy");
this.route("leadership");
this.route("staff");
this.route("affiliations");
});
this.route("conditions");
this.route("programs");
this.route("testimonials");
});
我无法在应用程序模板中呈现部分内容,因为我只希望它在有人位于 /about url 时显示。
我已经尝试过普通的旧 jQuery 显示和隐藏:
App.ApplicationController = Ember.ObjectController.extend({
currentRouteChanged: function() {
if(this.get('currentRouteName').indexOf('about') > -1) {
$("ul").removeClass("sub-nav-list-hide");
$("ul").addClass("sub-nav-list-show");
}
}.observes('currentRouteName')
});
当您单击 about 时它会起作用,但是当您单击后退按钮或导航到另一个页面时 subnav 不会隐藏。
我被困住了,我觉得我让这种方式太难了。