【问题标题】:Model Computed Property not updating模型计算属性未更新
【发布时间】:2016-03-07 14:33:58
【问题描述】:

除非刷新页面,否则计算属性 student.successfulEvaluations 为何不更新?

http://emberjs.jsbin.com/keduco/edit?html,js,output

App.Student = DS.Model.extend({
  username: DS.attr('string'),
  evaluations: DS.hasMany('evaluation'),
  successfulEvaluations: Ember.computed.filter('evaluations.@each.grade', function(evaluation, index, array){
    return evaluation.get('grade') >= 10;
  })
});

App.Evaluation = DS.Model.extend({
  subject: DS.attr('string'),
  grade:   DS.attr('number'),
  student: DS.belongsTo('student')
});

余烬:2.2.0
灰烬数据:2.2.1

【问题讨论】:

  • 在您的jsbin 中工作...

标签: javascript ember.js ember-data


【解决方案1】:

EmberJS 2.1/2.2 中似乎有一个关于@each computed properties 的错误。有一种解决方法是使用content.@each 而不是仅仅使用@each(有关详细信息,请参阅问题)

successfulEvaluations: Ember.computed.filter('evaluations.content.@each.grade', function(evaluation, index, array){
   return evaluation.get('grade') >= 10;
})

【讨论】:

    猜你喜欢
    • 2019-04-18
    • 2020-08-11
    • 2014-03-01
    • 2019-10-03
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多