Ember数据和脏记录 [英] Ember Data and dirty records

查看:82
本文介绍了Ember数据和脏记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有以下逻辑将脏记录还原到原始状态。

 如果controller.get('isDirty')
controller.get('content')。rollback()

除非提交记录未成功尝试,否则此功能



如果我尝试提交更改,并且服务器响应错误,则不可能以这种方式回滚记录。在这种情况下,Ember Data或RESTAdapter是否提供了将记录还原到其原始状态的内置方法?






我正在使用封装的 DS.RESTAdapter 与Ember Data revision 11

解决方案

我发现,虽然我不知道为什么,我看到的东西显然是有效的。这是我在我的模型中所做的:

  App.User = DS.Model.extend({

becomeInvalid:function(errors){
this.get('transaction')。rollback();
//this.rollback();& - - 这不工作,你得到了错误
}
});

来自 sly7-7 问题给了我想法。


What is the recommended way of discarding changes made to records?

I have the following logic to revert dirty records to their original state.

if controller.get('isDirty')
  controller.get('content').rollback()

This works unless an unsuccessful attempt has been made to commit the record.

If I try to commit the changes and the server responds with errors, it's no longer possible to rollback the record this way. In this case, does Ember Data or the RESTAdapter provide a built-in method of reverting the record to its original state?


I'm using the packaged DS.RESTAdapter with Ember Data revision 11

解决方案

I've found something that apparently works although I don't know why. Here is what I do in my model:

App.User = DS.Model.extend({

  becameInvalid: function(errors) {
    this.get('transaction').rollback();
    //this.rollback(); <- This doesn't work. You get becameClean error.
  }
});

The comment from sly7-7 for that issue gave me the idea.

这篇关于Ember数据和脏记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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