Ember.js 余烬数据-提交后isDirty为true
我试图在提交时保存表单,但在任何其他情况下放弃更改。问题是,即使在提交之后,isDirty标志也是真的Ember.js 余烬数据-提交后isDirty为true,ember.js,ember-data,Ember.js,Ember Data,我试图在提交时保存表单,但在任何其他情况下放弃更改。问题是,即使在提交之后,isDirty标志也是真的 App.UserController = Ember.Controller.extend({ enterEditing: function() { this.transaction = App.store.transaction(); this.transaction.add(this.get('content')); }, updateEditing: fun
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');
}
它实际上应该将
isDirty
和isSaving
保持为true,直到您的服务返回200。之后,两个标志都应自动设置为false。检查isSaving
标志,可能您的服务在您检查isDirty
时还没有完成保存,isSaving从false变为true,但isDirty保持true。我返回了一个带有node.js/express backend-res.jsonp(200)的200,我还看到了rc1上的FixtureAdapter