Ember-data - 提交后isDirty为true

时间:2012-12-18 15:58:01

标签: ember.js ember-data

我正在尝试在提交时保存表单,但在任何其他情况下都会丢弃更改。问题是即使在提交之后,isDirty标志也为真。

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');
  }

0 个答案:

没有答案