Ember.js 根据路线显示/隐藏主页按钮

Ember.js 根据路线显示/隐藏主页按钮,ember.js,Ember.js,我正在执行Ember.js中的第一步,我对社区中提供的不同方法和解决方案感到困惑 我有一个相当小的应用程序,它有一个应用程序模板和内容模板,我可以通过链接浏览这些模板 我的应用程序模板有一个“主页”按钮,我想根据导航到的路线隐藏和显示该按钮。我该怎么做 我使用的是普通的老JavaScript。无预处理器或类似程序。您可以在控制器中直接使用全局currentRouteName属性 hideHomeButtonRoutes: ['index', 'login'], isHomeButtonVisib

我正在执行Ember.js中的第一步,我对社区中提供的不同方法和解决方案感到困惑

我有一个相当小的应用程序,它有一个应用程序模板和内容模板,我可以通过链接浏览这些模板

我的应用程序模板有一个“主页”按钮,我想根据导航到的路线隐藏和显示该按钮。我该怎么做


我使用的是普通的老JavaScript。无预处理器或类似程序。

您可以在控制器中直接使用全局
currentRouteName
属性

hideHomeButtonRoutes: ['index', 'login'],
isHomeButtonVisible: Ember.computed('currentRouteName', function(){
  return this.get('hideHomeButtonRoutes').indexOf(this.get('currentRouteName')) > -1;
})
在应用程序控制器中

hideHomeButtonRoutes: ['index', 'login'],
isHomeButtonVisible: Ember.computed('currentRouteName', function(){
  return this.get('hideHomeButtonRoutes').indexOf(this.get('currentRouteName')) > -1;
})
在您的
模板中

{{#if isHomeButtonVisible}} <button>home</button> {{/if}}
{{{#if isHomeButtonVisible}}home{{/if}

这里正在工作

您可以直接在控制器中使用全局
currentRouteName
属性

hideHomeButtonRoutes: ['index', 'login'],
isHomeButtonVisible: Ember.computed('currentRouteName', function(){
  return this.get('hideHomeButtonRoutes').indexOf(this.get('currentRouteName')) > -1;
})
在应用程序控制器中

hideHomeButtonRoutes: ['index', 'login'],
isHomeButtonVisible: Ember.computed('currentRouteName', function(){
  return this.get('hideHomeButtonRoutes').indexOf(this.get('currentRouteName')) > -1;
})
在您的
模板中

{{#if isHomeButtonVisible}} <button>home</button> {{/if}}
{{{#if isHomeButtonVisible}}home{{/if}

此处正在运行

您可以为解决方案指定路径和控制器吗?我是否需要为应用程序的每个路由设置setupController?还是某种申请途径?控制器是一种应用程序控制器吗?这只在和主页按钮相同的级别上执行一次,如果是在应用程序模板中,请将所有内容放入应用程序路径中,控制器是这样的吗
App.ApplicationController=Ember.Controller.extend({hideHomeButtonRoutes:['index',intro',isHomeButtonVisible:Ember.computed('currentRouteName',function(){返回this.get('hideHomeButtonRoutes').indexOf(this.get('currentRouteName'))>1;});App.ApplicationRoute=Ember.Route.extend({setupController:function(controller,model){controller.set('currentRouteName',this.router.currentRouteName);},})不知何故不起作用。我不明白。抱歉,我错过了一些我正在更新的内容。回答也不起作用:/I我正在使用Ember.js 2.2。这重要吗?这里是我的代码:App.ApplicationController=Ember.Controller.extend({hideHomeButtonRoutes:['index',intro',isHomeButtonVisible:Ember.computed('currentRouteName',function(){return this.get('hideHomeButtonRoutes')。indexOf(this.get('currentRouteName'))>1;});App.ApplicationRoute=Ember.Route.extend({操作:{加载:函数(){if(this.controller){this.controller.set('currentRouteName',this.router.currentRouteName);}}});您能为您的解决方案在中指定路由和控制器吗?我是否需要为应用程序的每个路由设置setupController?还是某种申请途径?控制器是一种应用程序控制器吗?这只在和主页按钮相同的级别上执行一次,如果是在应用程序模板中,请将所有内容放入应用程序路径中,控制器是这样的吗
App.ApplicationController=Ember.Controller.extend({hideHomeButtonRoutes:['index',intro',isHomeButtonVisible:Ember.computed('currentRouteName',function(){返回this.get('hideHomeButtonRoutes').indexOf(this.get('currentRouteName'))>1;});App.ApplicationRoute=Ember.Route.extend({setupController:function(controller,model){controller.set('currentRouteName',this.router.currentRouteName);},})不知何故不起作用。我不明白。抱歉,我错过了一些我正在更新的内容。回答也不起作用:/I我正在使用Ember.js 2.2。这重要吗?这里是我的代码:App.ApplicationController=Ember.Controller.extend({hideHomeButtonRoutes:['index',intro',isHomeButtonVisible:Ember.computed('currentRouteName',function(){return this.get('hideHomeButtonRoutes')。indexOf(this.get('currentRouteName'))>1;});App.ApplicationRoute=Ember.Route.extend({操作:{加载:函数(){if(this.controller){this.controller.set('currentRouteName',this.router.currentRouteName);}}});