[英]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.