首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ember计算属性控制器

Ember计算属性控制器
EN

Stack Overflow用户
提问于 2014-04-11 18:54:39
回答 1查看 69关注 0票数 0

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

代码语言:javascript
运行
复制
App.Category = DS.Model.extend({
    translation_ids: DS.hasMany('translation', { embedded: 'always' }),
});

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

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

代码语言:javascript
运行
复制
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“属性不会更新:

我尝试了无数种不同的东西,但到目前为止都没有用。有人能指出我的错误吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-11 20:25:26

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23020510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档