EmberJS:如何POST,然后立即编辑 [英] EmberJS: how to POST, then edit immediately

查看:84
本文介绍了EmberJS:如何POST,然后立即编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下操作:

I am trying to do the following:


  • 创建一个对象(通过POST到服务器)

  • 然后立即在客户端上编辑它。

所以基本上这意味着UI可以保持不变 - 除了下一次提交被点击时,表单是PUT而不是POSTed。

So basically it means the UI could just stay the same - except the next time "submit" is clicked, the form is PUT instead of POSTed.

1-现在,一旦我提交表单,它将被刷新数据。

1- Right now, as soon as I submit the form, it is refreshed with new data.

为什么会这样做?

    App.FooNewRoute = Ember.Route.extend({
      ...
      events: {
        submit: function(){ 
            this.store.commit(); // The form content changes
        }
      }

    });

2-我的第一个,钝的做法做POST,然后编辑是调用

2- My first, blunt approach to do POST then Edit was to call

    this.transitionTo('foo.edit', this.get('controller').get('model'));

紧随

    this.store.commit();

但它不会工作,我明白为什么(对象仍然被保存 - 或者inFlight - )当我尝试编辑它。

but it won't work, and I understand why (the object is still "being saved" - or inFlight -) when I try to edit it.

但是如何才能完成?

谢谢!
PJ

Thanks! PJ

推荐答案

基本上,您需要等待交易在转换前完成。

Basically you'll need to wait for transaction to complete before transitioning.

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

这篇关于EmberJS:如何POST,然后立即编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆