在Ember中强制重新加载脏/无效模型 [英] Force reload of dirty/invalid model in Ember

查看:61
本文介绍了在Ember中强制重新加载脏/无效模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为目标记录建立编辑功能。在目标索引页面上,每个目标旁边都有一个编辑按钮。单击后,每个字段都可编辑。单击保存后,更改将保存到服务器。到现在为止还挺好。

I am trying to build out edit functionality for a Goal record. On the Goal index page, there is an edit button next to each goal. When clicked, each field becomes editable. Upon clicking Save, the changes are saved to the server. So far so good.

还有一个取消按钮。当用户单击它时,我需要将模型的状态重置为更改之前的状态。控制器中的 goal.rollback()可以正常工作。除非用户已经单击保存,但是服务器端验证失败。在这种情况下,尝试回滚()引发未捕获的错误:尝试处理< App.Goal:ember123:1234>上的事件`reloadRecord`。

There is also a Cancel button. When a user clicks it, I need to reset the state of the model to what it was before they changed things. goal.rollback() in the controller works fine for this. Except, if the user has already clicked Save but there were server side validation failures. In this case, attempting to rollback() throws Uncaught Error: Attempted to handle event `reloadRecord` on <App.Goal:ember123:1234> while in state root.loaded.updated.invalid.

如果相反,我尝试尝试 goal.reloadRecord 我收到未捕获的错误:尝试处理< App.Goal:ember123:1234>上的事件`reloadRecord`。

If instead I try to goal.reloadRecord I get Uncaught Error: Attempted to handle event `reloadRecord` on <App.Goal:ember123:1234> while in state root.loaded.updated.invalid.

goal.unloadRecord 。我尝试过这样按摩状态:

Same deal with goal.unloadRecord. I have tried massaging the state like this:

state = goal.get('currentState') #this code makes me sad.
state.isValid = true
state.isError = false

就像这样:

goal.transitionTo('loaded.saved')

无济于事。对我来说,重新加载或卸载记录应为statefull对我来说是零。

To no avail. Is make zero sense to me the reloading or unloading a record should be statefull.

任何帮助将不胜感激。再一次,我试图通过清除更改或只是从服务器重新加载,来在ember中获取肮脏的,无效的记录,并将其恢复到令人满意的状态。

Any assistance would be greatly appreciated. Again, I'm trying to take a dirty, invalid record in ember and get it back to a happy state either by rolling back changes, or just reloading it from the server.

编辑:Ember-data v1.0.0-beta.3-4-g169793e,灰烬版本:1.1.2

Ember-data v1.0.0-beta.3-4-g169793e, ember Version: 1.1.2

推荐答案

这是一个可行的示例,更改颜色然后单击保存。

Here's a working example, change the color then hit save.

http://emberjs.jsbin.com/OxIDiVU/44/edit

PR已提交 https://github.com/emberjs/data/pull/1590

这篇关于在Ember中强制重新加载脏/无效模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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