我正在尝试执行以下操作:
所以基本上它意味着UI可以保持不变 - 除了下次单击“提交”时,表单是PUT而不是POST。
1-现在,只要我提交表单,就会刷新新数据。
为什么会这样做?
App.FooNewRoute = Ember.Route.extend({
...
events: {
submit: function(){
this.store.commit(); // The form content changes
}
}
});
2-我的第一个,直截了当的做POST的方法然后编辑是打电话
this.transitionTo('foo.edit', this.get('controller').get('model'));
之后
this.store.commit();
但是它不起作用,我理解为什么(当我尝试编辑它时,对象仍然是“被保存” - 或者在“飞行中”)。
但怎么办呢?
谢谢! PJ
答案 0 :(得分:2)
基本上你需要在转换之前等待交易完成。
App.FooNewRoute = Ember.Route.extend({
...
events: {
submit: function(){
var foo,
_this = this;
foo = this.get('controller').get('model');
// Register a one-time callback for the 'didCreate' event
foo.one('didCreate', function() {
// At this point the model's id has not been set, so wait till next run loop
Ember.run.next(_this, function() {
// Now foo is ready, transition to edit
this.transitionTo("foo.edit", foo);
});
});
this.store.commit();
}
}
})