模型计算属性不更新 [英] Model Computed Property not updating
本文介绍了模型计算属性不更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算的属性student.successfulEvaluations不会更新,除非页面被刷新?
How come the computed property student.successfulEvaluations does not update unless the page is refreshed?
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
Ember : 2.2.0
Ember Data : 2.2.1
推荐答案
似乎在EmberJS 2.1 / 2.2中有一个错误 @每个计算属性。有一个解决方法是使用内容@每个
而不是 @each
(有关详细信息,请参阅问题) p>
There seems to be a bug in EmberJS 2.1/2.2 regarding @each computed properties. There's a workaround that's to use content.@each
instead of just @each
(See the issue for details)
successfulEvaluations: Ember.computed.filter('evaluations.content.@each.grade', function(evaluation, index, array){
return evaluation.get('grade') >= 10;
})
这篇关于模型计算属性不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文