Emberjs中止过渡并显示模态

Raj*_*jat 6 ember.js ember-router

我想在特定路线上中止过渡并显示模态.这是我的路线代码的样子:

export default Ember.Route.extend({
  model: {/* some code here */},
  actions: {
    willTransition: function(transition) {
      if (!this.controller.get('model.name')) {
        console.log('aborting transition');
        transition.abort();
        this.send('showModal', {
          template: 'campaign/campaign-name-modal',
          controller: this.controller,
          model: this.controller.get('model')
        });
      }
      else {
        // Bubble the `willTransition` action so that
        // parent routes can decide whether or not to abort.
        return true;
      }
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

然后在我application.hbs,我有:

{{outlet 'modal'}}
Run Code Online (Sandbox Code Playgroud)

我所观察到的是过渡中止但我modal没有出现.当我将订单切换为以下内容时:

    this.send('showModal', {
      template: 'campaign/campaign-name-modal',
      controller: this.controller,
      model: this.controller.get('model')
    });
    console.log('aborting transition');
    transition.abort();
Run Code Online (Sandbox Code Playgroud)

转型根本不会中止.

我不确定为什么会发生这种情况.有什么指针吗?

小智 1

也许尝试编辑条件以使用firstObject:

if (!this.controller.get('model.firstObject.name')) {
Run Code Online (Sandbox Code Playgroud)