Alertify不使用路线的Ember过渡

时间:2017-07-19 02:00:25

标签: ember.js ember-cli alertify alertifyjs

当有人试图从页面导航时,我正在尝试使用alertify确认框。但是在路径的willTransition操作中,alertify非常异步,并且ember不会等待确认。无论您点击什么,页面都已导航。

willTransition(transition) {
  alertify.confirm('Confirm', 'Are you sure you want to navigate?', function(e) {
    if(e) {
     return true;
    } else {
     transition.abort();
    }
  });
}

请帮帮我!!

1 个答案:

答案 0 :(得分:0)

您可以中止并重试转换。您必须在显示确认对话框之前中止转换。确认对话框后,您可以重试转换并阻止代码再次显示确认对话框。所以以下内容应该有效(未经测试):

export default Ember.Route.extend({

  // ...

  showConfirmation: true,

  actions: {
    willTransition(transition) {
      if(!this.get('showConfirmation')) {
        this.set('showConfirmation', true);
        return true;
      }
      // Abort the transition for now
      transition.abort();

      // Now show a confirm box with alertify.
      // According to the docs, only the following 
      // is allowed: http://alertifyjs.com/confirm.html

      alertify.confirm('Are you sure you want to navigate?', () => {   
        // According to the documentation of alertify, 
        // this code is only run when you confirm your box.
        this.set('showConfirmation', false);
        transition.retry();
      });
    }
  }
}