首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Alertify不使用路由中的Ember转换

Alertify不使用路由中的Ember转换
EN

Stack Overflow用户
提问于 2017-07-19 10:00:25
回答 1查看 107关注 0票数 0

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

代码语言:javascript
复制
willTransition(transition) {
  alertify.confirm('Confirm', 'Are you sure you want to navigate?', function(e) {
    if(e) {
     return true;
    } else {
     transition.abort();
    }
  });
}

请帮帮我!

EN

回答 1

Stack Overflow用户

发布于 2017-07-19 14:53:50

您可以中止并重试转换。在显示确认对话框之前,必须中止转换。确认对话框后,可以重试转换并阻止代码再次显示确认对话框。因此,以下代码应该可以工作(未经过测试):

代码语言:javascript
复制
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();
      });
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45179778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档