【问题标题】:Ember computed properties controllerEmber 计算属性控制器
【发布时间】:2014-05-26 01:50:09
【问题描述】:

我有一个与多个翻译有一对多关系的模型:

App.Category = DS.Model.extend({
    translation_ids: DS.hasMany('translation', { embedded: 'always' }),
});

App.Translation = DS.Model.extend({
    name: DS.attr(),
    locale: DS.attr()
});

我想根据所选语言获取类别名称:

App.CategoryController = Ember.ObjectController.extend({   
    needs: ['settings'],
    currentLocale: Ember.computed.alias('controllers.settings.currentLocale'),
    name: function() {
        var translations = this.get('translation_ids').filterBy('locale', this.get('currentLocale'));
        Ember.assert("Only one translation is expected", translations.length === 1);
        return translations[0].get('name');
    }.property('translation_ids') 
});

一切都很顺利。但是当我编辑我的类别时,“名称”属性不会更新:

我已经尝试了一百万种不同的方法,但到目前为止都没有任何效果。有人能指出我的错误吗?

【问题讨论】:

    标签: ember.js ember-data


    【解决方案1】:

    translation_ids 是一个数组,所以你要观察数组中的元素,而不仅仅是数组本身。使用.property('translation_ids.@each')

    【讨论】:

      猜你喜欢
      • 2017-05-21
      • 2014-08-19
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多