Joa*_*eie 5 transactions ember.js ember-data
我已经实现了一个有交易的Route.当用户通过单击"后退"按钮移出此路径时,我希望用户能够确认退出并丢失通过回滚事务所做的任何更改.
问题是,如果用户返回到路由,Ember Data会引发错误并指出:
Error: assertion failed: Models cannot belong to more than one transaction at a time.
Run Code Online (Sandbox Code Playgroud)
这是即使我在旧事务上显式调用remove()并将add()添加到新事务(请参阅下面的newTransaction()函数):
settingsDetails: Ember.Route.extend({
route: '/details',
transaction: MyApp.store.transaction(),
doBackButton: function() {
var dirty = MyApp.router.get('settingsDetailsController.content.isDirty');
var doTransition = true;
if (dirty) {
var confirmDialog = confirm('You have unsaved changes. Are you sure you want to continue ? \n\nAny chances made will be lost!');
doTransition = confirmDialog;
}
if (doTransition) {
this.doResetSettingsDetails();
MyApp.router.transitionTo('settings.settingsOverview');
}
},
newTransaction: function() {
var oldTransaction = this.get('transaction');
var newTransaction = MyApp.store.transaction();
var record = MyApp.router.get('settingsDetailsController').get('content');
if (record) {
oldTransaction.remove(record);
newTransaction.add(record);
}
this.set('transaction', newTransaction);
},
doUpdateSettingsDetails: function() {
this.get('transaction').commit();
this.newTransaction();
},
doResetSettingsDetails: function() {
this.get('transaction').rollback();
this.newTransaction();
},
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('settingsDetails');
var record = MyApp.store.find(MyApp.PersonDetails, 1);
this.get('transaction').add(record);
router.get('settingsDetailsController').set('content', record);
}
}),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
669 次 |
| 最近记录: |