送信時にフォームを保存しようとしていますが、それ以外の場合は変更を破棄します。問題は、コミット後でも isDirty フラグが true であることです。
App.UserController = Ember.Controller.extend({
enterEditing: function() {
this.transaction = App.store.transaction();
this.transaction.add(this.get('content'));
},
updateEditing: function() {
console.log('update saved');
this.transaction.commit();
this.transaction = null;
}
});
App.UserView = Ember.View.extend({
templateName: 'edit-user',
willDestroyElement: function() {
console.log(this.getPath('controller.content.isDirty'));
if (this.getPath('controller.content.isDirty')) {
console.log('unsaved changes');
this.getPath('controller.content.transaction').rollback();
}
}
});
そして私のルーターセクション:
showNew: Ember.Route.extend({
route: '/user/new',
cancelEditUser: Ember.Route.transitionTo('index'),
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('user');
router.get('userController').enterEditing();
}
}),
update: function(router, event) {
router.get('userController').updateEditing();
router.transitionTo('index');
}