简体   繁体   中英

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.

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 ?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM