0

免责声明:我对 Ember 还很陌生,所以请放轻松。:)

如果 App.get('currentPath') 的值设置为'index',我正在尝试在应用程序视图的 div 上显示一个“is-home”的类。下面的代码用于设置类,但是,它只加载时这样做。如果您加载页面并单击链接,则如果您离开主页,则不会重新运行逻辑以删除该类,或者如果您在其他页面上输入但随后导航到主页,则不会添加它。我确信我错过了一些简单的东西。

任何帮助将不胜感激!

当前代码(注意:我使用的是 Ember App Kit)

// app/views/application.js

export default Ember.View.extend({
  classNameBindings: ['isHome'],
  isHome: function() {
    if (App.get('currentPath') == 'index') {
      return true;
    } else {
    return false;
    }
  }.property()
});

App.get('currentPath') 的功能源自此答案https://stackoverflow.com/a/18302740/3403881

4

1 回答 1

0

您必须告诉属性在currentPath属性更改时更新。

isHome: function() { ... }.property('currentPath')

但是,我不能 100% 确定它是否会currentPath在视图上找到该属性,因为它在技术上存在于控制器上。您可能不得不观看controller.currentPath

于 2014-03-11T00:33:11.900 回答