[英]Error Attempted to handle event `loadedData` : Object not updated after deleteRecord
Using the last version of ember-js and ember-data, I got an issue when deleting a record. 使用最新版本的ember-js和ember-data,删除记录时出现问题。
My route : 我的路线:
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);
}
}
});
When deleting a contact, I'm going back to the ListContactsRoute , so a call is made to the API wich returns me a list of contacts. 删除联系人时,我将返回到ListContactsRoute ,因此对API的调用将向我返回联系人列表。 At this point, the deleted contact hasn't been deleted on the server yet. 此时,已删除的联系人尚未在服务器上删除。
In result, the deleted contact is still present on my contacts list template. 结果,已删除的联系人仍然存在于我的联系人列表模板中。 Here's the error : 这是错误:
"Uncaught Error: Attempted to handle event `loadedData` on <App.Contact:ember469:null> while in state rootState.deleted.inFlight. Called with undefined"
Am I doing something wrong or is there a way to fix this ? 我做错了什么还是有办法解决?
The record is no longer part of the this.transaction
, once you commit a transaction a record is moved to the store default transaction. 记录不再是this.transaction
一部分,一旦您提交了一个事务,一条记录便被移至商店默认事务。 To reflect your deletion action, you need to commit the store. 为了反映您的删除操作,您需要提交存储。
contact.deleteRecord()
App.store.commit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.