[英]Uncaught Error: Attempted to handle event `loadedData` while in state rootState.loaded.updated.uncommitted
[英]Error Attempted to handle event `loadedData` : Object not updated after deleteRecord
使用最新版本的ember-js和ember-data,刪除記錄時出現問題。
我的路線:
App.ListContactsRoute = Em.Route.extend({
model: function() {
App.Contact.find();
},
setupController: function(controller, model) {
controller.set('contacts', model);
}
});
App.EditContactRoute = Em.Route.extend({
setupController: function(controller, model) {
this.transaction = controller.get('store').transaction();
this.transaction.add(model);
controller.set('content', model);
controller.set('organizations', App.Organization.find());
},
events: {
delete: function(contact) {
contact.deleteRecord();
this.transaction.commit();
this.transaction = null;
this.transitionTo("listContacts");
},
save: function(contact) {
this.transaction.commit();
this.transaction = null;
this.transitionTo("editContact", contact);
}
}
});
刪除聯系人時,我將返回到ListContactsRoute ,因此對API的調用將向我返回聯系人列表。 此時,已刪除的聯系人尚未在服務器上刪除。
結果,已刪除的聯系人仍然存在於我的聯系人列表模板中。 這是錯誤:
"Uncaught Error: Attempted to handle event `loadedData` on <App.Contact:ember469:null> while in state rootState.deleted.inFlight. Called with undefined"
我做錯了什么還是有辦法解決?
記錄不再是this.transaction
一部分,一旦您提交了一個事務,一條記錄便被移至商店默認事務。 為了反映您的刪除操作,您需要提交存儲。
contact.deleteRecord()
App.store.commit();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.