将更改恢复为余烬数据模型 [英] Revert change to ember data model

查看:94
本文介绍了将更改恢复为余烬数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一种方法可以轻松地将更改还原为Ember Data模型?我有一个模型绑定到编辑视图。该视图使用户能够取消编辑,此时我想将更改还原到模型。有没有一个简单的方法来做到这一点,而不是克隆所有的价值观?

解决方案

Ember Data支持交易的概念。我们可以创建一个事务并为它们分配Ember数据记录,如果我们想撤消这些更改,我们可以调用事务rollback()方法。另外,如果我们不创建一个显式事务,记录将被分配给一个默认事务,可以通过在DS.store对象本身上调用rollback()方法来回滚。


Is there a way to revert a change to an Ember Data model easily?

I have a model bound to an edit view. This view enables the user to cancel editing, at which point I'd like to revert the changes to the model. Is there an easy way to do this without cloning all the values off the side?

解决方案

Ember Data supports the concept of transactions. We can create a transaction and assign Ember data records to them and if we want to undo the changes we can call the transactions rollback() method. Also if we do not create an explicit transaction the records are assigned to a default transaction which can be rolled back by calling the rollback() method on the DS.store object itself.

这篇关于将更改恢复为余烬数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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