2017-07-19 54 views
0

我想,當有人試圖從頁面導航使用alertify確認框。但在路線的willTransition行動,alertify非常異步的,餘燼不會等待確認。無論您點擊什麼,該頁面都已被導航。Alertify不與Ember轉換工作從路線

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

請幫我這個!

回答

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