模型计算属性未更新

时间:2015-12-03 04:59:50

标签: javascript ember.js ember-data

为什么计算属性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')
});
  

Ember:2.2.0
  Ember数据:2.2.1

1 个答案:

答案 0 :(得分:2)

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;
})