Ember Data Model rollback not working on custom attribute of model

时间秒杀一切 提交于 2019-12-11 11:04:19

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/24344574/ember-data-model-rollback-not-working-on-custom-attribute-of-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!