Ember数据模型回滚不适用于模型的自定义属性 [英] Ember Data Model rollback not working on custom attribute of model
问题描述
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屋!