如何知道为什么记录在余烬数据中是脏的

Ria*_*iad 3 ember.js ember-data

有没有办法知道为什么记录在ember数据中处于脏状态,我的意思是什么是已经改变的属性和关系.

调用findAll之后我有isDirty = true,我想调试为什么会这样.

非常感谢

Mel*_*ers 7

从Ember-Data beta 6或更早版本开始,有一个changedAttributes()函数可以返回已更改的属性的哈希值及其初始值/当前值.见http://emberjs.com/guides/models/working-with-records/

例如:

person.changedAttributes(); //=> { isAdmin: [false, true] }
Run Code Online (Sandbox Code Playgroud)

请注意,这changedAttributes()不是您可以观察到的属性; 但是,如果您需要这样做,您可以观察模型上可能更改的所有属性,然后检查changedAttributes()计算属性/观察函数内部.

对于(人为的)例子:

checkAttributes: (->
  changed = @get('model').changedAttributes()
  if changed['name'] && Object.keys(changed).length == 1
    # Do something if name is the only changed attribute
).property('name', 'alias', 'description')
Run Code Online (Sandbox Code Playgroud)