我有一个模型,它与多个翻译有一对多的关系:
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')
});一切都很顺利。但是,当我编辑类别时,"name“属性不会更新:

我尝试了无数种不同的东西,但到目前为止都没有用。有人能指出我的错误吗?
发布于 2014-04-11 20:25:26
translation_ids是一个数组,所以您希望观察数组中的元素,而不仅仅是数组本身。使用.property('translation_ids.@each')。
https://stackoverflow.com/questions/23020510
复制相似问题