简体   繁体   English

尝试处理事件`loadedData`时出错:deleteRecord之后对象未更新

[英]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. 删除联系人时,我将返回到ListContactsRou​​te ,因此对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.

相关问题 未捕获错误:在状态rootState.loaded.updated.uncommitted中尝试处理事件`loadedData` - Uncaught Error: Attempted to handle event `loadedData` while in state rootState.loaded.updated.uncommitted deleteRecord后列表未更新 - List not updated after deleteRecord Ember-data - “在状态root.deleted.saved中尝试在* record *上处理事件`deleteRecord`。” - Ember-data - “Attempted to handle event `deleteRecord` on *record* while in state root.deleted.saved.” 灰烬未捕获的错误:试图处理事件`didSetProperty` - Ember Uncaught Error: Attempted to handle event `didSetProperty` 错误:删除记录模型余烬时尝试处理事件`didSetProperty` - Error: Attempted to handle event `didSetProperty` when Deleting record model ember 在状态root.loaded.updated.inFlight中尝试处理事件`willCommit` - Attempted to handle event `willCommit` on while in state root.loaded.updated.inFlight 为什么在Ember中成功完成deleteRecord后出现错误 - Why am I getting an error after successful deleteRecord in Ember 尝试处理事件“ pushedData” <testapp@model:testroute::ember1700:1> 处于状态root.loaded.updated.invalid时 - Attempted to handle event `pushedData` on <testapp@model:testroute::ember1700:1> while in state root.loaded.updated.invalid EmberJS在deleteRecord和保存后抛出未定义 - EmberJS throws undefined after deleteRecord and save Deleterecord不会从HasMany数组中删除对象 - Deleterecord is not deleting object from the HasMany array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM