我在卸载数据模型时遇到问题,并在进行API调用时正确地重新填充数据模型。
模特:
/* Model Foo */
export default DS.Model.extend({
bars: DS.hasMany('bar', { async: true })
});
/* Model Bar */
export default DS.Model.extend({
foo: DS.belongsTo('foo', { async: true, inverse: 'bars' })
});
在app中的某个点,foo和bar都从ember数据存储中卸载,然后从API调用重新加载。像这样:
/* Unload and reload snippet */
this.store.unloadAll('bar');
this.store.unloadAll('foo');
let bars = this.store.filter('bar', {
queryParam: x
}, function(bar) {
return x === bar.x
});
let foos = this.store.filter('foo', {
queryParam: y
}, function(foo) {
return y === bar.y
});
let self = this;
Ember.RSVP.all([foos, bars]).finally(function() {
self.controller.set('model.foos', foos);
self.controller.set('model.bars', bars);
});
问题出现在依赖于这些模型更改的计算属性中。
/* Computed property elsewhere in app */
compProp: Ember.computed('foo.bars.[]', function() {
let tmp = this.get('foo.bars'); /* <-- Error generating line */
.
.
.
})
这一行给出了以下错误:
Assertion Failed: calling set on destroyed object: <DS.PromiseManyArray:ember1995>.content = <DS.ManyArray:ember3320>
错误的堆栈跟踪:
Assertion Failed: calling set on destroyed object: <DS.PromiseManyArray:ember1014>.content = <DS.ManyArray:ember1348>
Error
at assert (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:23072:13)
at Object.assert (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:23285:34)
at Object.set (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39281:17)
at Class.set (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:52151:26)
at ManyRelationship._updateLoadingPromise (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:152522:33)
at ManyRelationship.getRecords (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:152723:21)
at Class.get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:152101:60)
at ComputedPropertyPrototype.get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:34367:28)
at get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39184:19)
at _getPath (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39205:13)
at Object.get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39180:14)
感谢您的帮助!
附注:
store.filter()
已被弃用。我是从早期的Ember版本升级应用程序并使用ember-data-filter插件来实现临时兼容性的。 为了不让这个问题公开,我从来没有找到问题。
我的解决方案是删除所有unloadAll()
个电话,并根据需要单独管理记录。
答案 0 :(得分:1)
这可能是由在ember上销毁的元素上发生的任何异步set
引起的。因此,追踪可能很棘手。我经常打开&#34;暂停捕获的异常&#34;在谷歌开发者控制台中找到导致问题的set
。