Ember数据:如何设置isDirty记录? [英] Ember Data: how to set isDirty for a record?

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

问题描述



可以在 c>细节 attr中进行编辑,而不会改变实际的对象引用(例如,详细信息attr上的子细节被编辑)。但是,这不会触发父记录的 isDirty 标志。



我如何手动通知一个DS.Model记录被更新?



模型定义:

  App.MyRecord = DS.Model.extend 
详细信息:DS.attr递归对象

编辑详细信息

 #记录是App.MyRecord的实例
#更改记录的详细信息attr
record.makeChangeToDetails()
record.get('isDirty')#仍然为false,因为Ember不知道子细节改变了。

我尝试过的东西:



包裹 record.makeChangeToDetails()将/ didSetProperty 调用:

  record.send'willSetProperty',name:'details'
record.makeChangeToDetails()
record.send'didSetProperty' ,名称:'details'

调用 notifyPropertyChange

  record.notifyPropertyChange'details'

调用设置并传递相同的对象

  record.makeChangeToDetails()
record.set'details',record.get('details')

我也尝试从这里发送各种其他DS.model状态事件: https://github.com/emberjs/data/blob/master/packages/ember-data/lib /system/model/states.js
包括 didChangeData becomeDirty 但这些



任何想法?

解决方案

我有一些线索这个其他问题:如何使用ember-data手动设置对象状态进行清理(保存)



特别是关于:




record.get('stateManager')。transitionTo('loaded.saved')


I have a details: DS.attr('recursive_object') custom transformation (it's a recursive object).

The details attr can be edited in place, without the actual object reference changing (e.g., a sub-detail on the details attr is edited). This, however, doesn't trigger the parent record's isDirty flag.

How can I manually notify a DS.Model record that it's been updated?

Model definition:

App.MyRecord = DS.Model.extend
  details: DS.attr "recursive object"

Editing details

# record is an instance of App.MyRecord
# makes a change to the record's details attr 
record.makeChangeToDetails()
record.get('isDirty') # still false because Ember doesn't know that a sub-detail changed.

Things I've tried:

Wrapping record.makeChangeToDetails() with will/didSetProperty calls:

record.send 'willSetProperty', name: 'details'
record.makeChangeToDetails()
record.send 'didSetProperty', name: 'details'

Calling notifyPropertyChange

record.notifyPropertyChange 'details'

Calling set and passing it the same object

record.makeChangeToDetails()
record.set 'details', record.get('details')

I've also tried sending various other DS.model states events from here: https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/states.js including didChangeData, becameDirty but none of these worked.

Any ideas?

解决方案

I got some clues from this other question: How to manually set an object state to clean (saved) using ember-data

In particular, the bit about:

record.get('stateManager').transitionTo('loaded.saved')

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

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