Ember数据模型回滚不适用于模型的自定义属性 [英] Ember Data Model rollback not working on custom attribute of model

查看:97
本文介绍了Ember数据模型回滚不适用于模型的自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个JS bin。有没有人知道为什么,当我修改用户模型并单击按钮回滚,为什么firstName属性正在回滚,但不是数组自定义属性?谢谢。



http://emberjs.jsbin.com/nunihuco/1/edit?html,js,console,output

解决方案

Ember Data手表属性本身。属性本身没有改变,你的数据是。您需要更改属性才能够 rollback

  this.set('model.listOfStuff',['hello','world']); 

http://emberjs.jsbin.com/nunihuco/2/edit



如果需要,您可以克隆和修改。这只适用于原始类型,但如果你有对象,你会遇到同样的事情。

  var orig = this .get('listOfStuff'),
newArr = orig.slice();
this.set('listOfStuff',newArr);
newArr [0] ='asdf';

http://emberjs.jsbin.com/nunihuco/3/edit


I have this JS bin. Does anyone know the reason why, when I modify the user model and click the button to rollback, why the firstName property is being rolled back but not the array custom attribute? Thanks.

http://emberjs.jsbin.com/nunihuco/1/edit?html,js,console,output

解决方案

Ember Data watches the property itself. The property itself isn't changing, your data inside is. You'd need to change the property for it to be able to rollback.

this.set('model.listOfStuff', ['hello','world']);

http://emberjs.jsbin.com/nunihuco/2/edit

If you wanted, you could clone and modify. This only works on primitive types though, if you have objects, you'd run into the same thing.

  var orig = this.get('listOfStuff'),
      newArr = orig.slice();
  this.set('listOfStuff', newArr);
  newArr[0] = 'asdf';

http://emberjs.jsbin.com/nunihuco/3/edit

这篇关于Ember数据模型回滚不适用于模型的自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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