我有一个项目评论列表,我的模板显示了最新的,带有一个按钮,可以调出一个模式来显示所有评论。在该模式中,您可以单独删除评论,这很有效,并且模式会相应地更新。模板也会更新,直到我删除最后一条记录。
这是我最初的财产声明:
mostRecentComment: Ember.computed('projectComments.firstObject', function() {
return get(this, 'sortedProjectComments.firstObject');
})
即使我查询了控制器并确认 firstObject 未定义,计算的属性仍然保持其值。
如果我更改计算属性以观看 @each 评论,如下所示:
mostRecentComment: Ember.computed('projectComments.@each.projectComment', 'projectComments.firstObject', function() {
return get(this, 'sortedProjectComments.firstObject');
})
然后视图会更新,但控制台会输出一个丑陋的错误:
Error: No model was found for '0'
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:18042:23)
at Ember.Object.extend.modelFor (http://localhost:4200/assets/vendor.js:75114:19)
at __exports__.default.JSONSerializer.extend.extractSingle (http://localhost:4200/assets/vendor.js:68260:28)
at apply (http://localhost:4200/assets/vendor.js:23073:27)
at superWrapper [as extractSingle] (http://localhost:4200/assets/vendor.js:22647:15)
at __exports__.default.Ember.Object.extend.extractSave (http://localhost:4200/assets/vendor.js:67828:21)
at __exports__.default.Ember.Object.extend.extractDeleteRecord (http://localhost:4200/assets/vendor.js:67779:21)
at __exports__.default.Ember.Object.extend.extract (http://localhost:4200/assets/vendor.js:67665:37)
at http://localhost:4200/assets/vendor.js:75760:32
删除最后一条记录后如何更新视图?还是我应该忽略这个错误?