Error Attempted to handle event `loadedData` : Object not updated after deleteRecord

为君一笑 提交于 2019-12-20 06:48:19

问题


Using the last version of ember-js and ember-data, I got an issue when deleting a record.

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. 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 ?


回答1:


The record is no longer part of the this.transaction, once you commit a transaction a record is moved to the store default transaction. To reflect your deletion action, you need to commit the store.

contact.deleteRecord()
App.store.commit();


来源:https://stackoverflow.com/questions/14319205/error-attempted-to-handle-event-loadeddata-object-not-updated-after-deletere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!