错误尝试处理事件`loadedData`:对象在deleteRecord之后未更新 [英] Error Attempted to handle event `loadedData` : Object not updated after deleteRecord

查看:168
本文介绍了错误尝试处理事件`loadedData`:对象在deleteRecord之后未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最后一个版本的ember-js和ember-data,在删除记录时遇到问题。

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

我的路线:

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

删除联系人时,我将返回到 ListContactsRou​​te 所以打电话给API,它给我一个联系人列表。此时,已删除的联系人尚未在服务器上删除。

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"

我做错了或在那里

推荐答案

记录不再是 this.transaction ,一旦你提交一个事务记录被移动到商店默认事务。要反映您的删除操作,您需要提交商店。

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

这篇关于错误尝试处理事件`loadedData`:对象在deleteRecord之后未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆