【问题标题】:How to get current Ember app route from template如何从模板获取当前的 Ember 应用程序路由
【发布时间】:2014-02-16 04:19:47
【问题描述】:

我正在尝试根据当前路由设置元素类属性。这是在应用程序把手模板中包含的导航把手部分内。

在我的 ApplicationController 中,我可以执行以下操作:

isUsers: ( ->
  @get('currentPath') == 'users.index'
).property('currentPath')

在导航模板中,我想执行以下操作:

<a {{bind-attr class="isUsers:active:inactive"}} href="users"></a>

这不起作用 - 始终设置非活动类,即使在正确的应用路径中也是如此。

有什么建议吗?

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    如果您在 ApplicationController 中定义 isUsers 属性,那么您确定在 application.handlebars 或 ApplicationController 使用的任何模板中使用它吗?如果您在具有不同控制器的模板中使用,请确保在控制器中使用以下内容。

    App.MyController = App.Controller.extend
      needs: ['application']
    

    在模板中,

    controllers.application.isUsers
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-30
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      相关资源
      最近更新 更多