简体   繁体   English

单一数据持久性与余烬数据

[英]Single record persistence with ember-data

In Ember.js with ember-data (using the 1.0pre versions) all changes to the data are saved into a defaultTransaction on the store. 在具有ember-data的Ember.js(使用1.0pre版本)中,对数据的所有更改都保存到商店的defaultTransaction中。 When the store is committed with store.commit() ALL changes to the data are saved back to the API (using the RESTAdapter). 使用store.commit()提交存储后,对数据的所有更改都将保存回API(使用RESTAdapter)。

I would like more control over objects being persisted. 我希望对保留的对象有更多控制。 So for now, I have been getting instances of store and adapter, then calling something like adapter.createRecord(store, type, record) or updateRecord where type is the App.Person model and record is an instance of that model. 所以现在,我一直在获取store和adapter的实例,然后调用诸如adapter.createRecord(store, type, record)updateRecord typeApp.Person ,其中typeApp.Person模型,而record是该模型的实例。

This is using internal bits of the DS.RESTAdapter that I don't think are meant to be used directly. 这使用的是DS.RESTAdapter内部位,我认为这些位不能直接使用。 While it works I'm hoping there is a better way to gain more control over persistence then store.commit() . 当它起作用时,我希望有一个更好的方法来获得对持久性的更多控制,然后是store.commit() The business logic and UX of my application require finer control. 我的应用程序的业务逻辑和UX需要更好的控制。

transaction = router.get('store').transaction();
person = transaction.createRecord(App.Person);

person.set('name', 'Thanatos');

transaction.commit();

watch yehuda presentation regarding this. 观看yehuda演示。 http://www.cloudee.com/preview/collection/4fdfec8517ee3d671800001d http://www.cloudee.com/preview/collection/4fdfec8517ee3d671800001d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM