灰烬数据

编程入门 行业动态 更新时间:2024-10-28 19:29:49
本文介绍了灰烬数据-如果离开表单,则会回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的应用程序具有用于从后端读取的一组实体的新的/编辑表单。

My application has new / edit forms for a set of entities read from a backend.

当我打开这样的表单并填写/编辑一些字段时,然后浏览,即使我没有提交这些更改,记录也会在实体列表中显示为已更改。重新加载应用程序(从后端重新加载数据)解决了该问题,但不是一种选择。

When I open such a form, and fill out / edit some fields, then navigate away, the records appear changed in the entity lists, even though I did not commit those changes. Reloading the app (which reloads the data from the backend) fixes the issue, but is not an option.

我尝试过在表单视图的willDestroyElement中进行一些事务回滚,但这似乎根本上是错误的,因为即使在成功提交表单后它也会被调用(并且实际上在崩溃,试图在状态rootState.loaded.updated.inFlight 下处理X上的事件回滚)。

I've tried doing some transaction rollbacks in the form view's willDestroyElement, but this seems fundamentally wrong since it gets called even after successful form submits (and actually crashes with Attempted to handle event rollback on X while in state rootState.loaded.updated.inFlight).

对于涉及导航的所有用例,我将如何忽略所有未提交的表单更改(类似于按取消按钮,这将执行事务回滚)

How would I go about ignoring all unsubmitted form changes (similar to pressing the Cancel button, which performs a transaction rollback), for any use case that involves navigating away from the forms?

使用Ember rc5,Ember Data 0.13。

Using Ember rc5, Ember Data 0.13.

推荐答案

退出表单路径时,请检查记录的状态。如果它的(isNew OR isDirty)和它的NOT isSaving,则回滚:

When exiting the form route, check the state of the record. If its (isNew OR isDirty) and its NOT isSaving, rollback:

App.FormRoute = Ember.Route.extend({ deactivate: function() { var model = this.controllerFor('form'); if ( (model.get('isNew') || model.get('isDirty')) && (!model.get('isSaving')) ) { model.rollback(); } } });

更多推荐

灰烬数据

本文发布于:2023-10-19 19:34:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508553.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:灰烬   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!