[英]Attempted to handle event `pushedData` on <appname@model:post::ember622:17> while in state root.deleted.inFlight
我有一个用于博客帖子的基本 crud 应用程序。上面的错误显示在控制台中。删除帖子后。但是帖子被从数据库中删除了。我搜索了类似的问题,但没有一个答案解决了这个问题。我使用用于 crud 操作的JSONAPIAdapter 。
我检查了 ember 检查器中的标志, isDeleted的标志设置为true。仅供参考, ember 数据中显示的记录数是精确的。
deletePost:function(id){
var self = this;
this.get('store').find('post', id)
.then(post => post.destroyRecord())
.then(() => self.transitionToRoute('posts'));
}
我使用 nodejs 作为后端,使用 mysql 作为 db。删除记录后,我发送这样的响应res.status(204).end();
Ember CLI 版本 2.6.3
我很确定这个问题是由 ember 数据的后台重新加载引起的。 即使在删除请求之前触发了对 api 的查找请求,在您触发删除请求之后,查找请求也会得到解决。 要禁用后台重新加载并强制进行 api 调用,您可以将{reload: true}
传递给findRecord()
调用。 这将确保在您触发删除请求之前解决查找请求。
像这样:
deletePost(id) {
this.get('store').findRecord('post', id, { reload: true }).then((post) => {
return post.destroyRecord();
}).then(() => {
self.transitionToRoute('posts');
});
}
您可以在此处阅读有关findRecord
更多信息: http : findRecord
将来,我建议不要使用箭头函数简写,因为即使您不想返回值,它也会始终返回。
我来过这里几次寻找解决方案。 我实际上在这里找到了更好的答案。 他们推荐的方法是使用 peekRecord 而不是 findRecord(假设该项目已经在商店中),这将是同步的。 那里的代码:
// get the comment from the store synchronously, without triggering a fetch
let comment = store.peekRecord("comment", commentId);
// check if there is a comment; is null in the case the store has no comment
with the given id
if (comment) {
comment.destroyRecord(...);
}
这对我有用,而{reload: true}
没有。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.