Ember.js 拒绝基于用户输入的转换,无需确认()
如何通过willTransition拒绝即将到来的转换,但使用自定义弹出窗口或jQuery。对话框如下:Ember.js 拒绝基于用户输入的转换,无需确认(),ember.js,Ember.js,如何通过willTransition拒绝即将到来的转换,但使用自定义弹出窗口或jQuery。对话框如下: willTransition: function(transition) { //Some conditional logic would go here to determine if they need to be prompted to save $("#confirmTransition").dialog({ resizable: false,
willTransition: function(transition) {
//Some conditional logic would go here to determine if they need to be prompted to save
$("#confirmTransition").dialog({
resizable: false,
modal: true,
draggable: false,
buttons: {
"Yes": function() {
self.transitionTo(transition.targetName);
$(this).dialog( "close" );
},
"No": function() {
transition.abort();
$(this).dialog( "close" );
}
}
});
}
而不是使用confirm(),后者实际上会等待用户输入某些内容。我可以使用.then,但它会在转换完成后激发。在所有路由上使用beforeModel来处理条件中止,然后依靠willTransition提供弹出窗口进行确认,这样会更好吗
根据接受的问题更新:
willTransition: function(transition) {
//Some conditional logic would go here to determine if they need to be prompted to save
var self = this;
if(!self._transitioning){
$("#confirmTransition").dialog({
resizable: false,
modal: true,
draggable: false,
buttons: {
"Yes": function() {
self._transitioning = true;
transition.retry().then(self._transitioning = false);
$(this).dialog( "close" );
},
"No": function() {
transition.abort();
$(this).dialog( "close" );
}
}
});
}
}
您可以使用相同的方法设置路线过渡动画:您可以查看(以及博客中提到的) 基本上,您在
willTransition
操作中处理一个小状态机:您中止原始转换,一旦用户关闭对话框,您就重试原始转换
希望有帮助 太棒了!我以前尝试过整个abort()和retry(),但它也会中止重试。因此,在调用之间切换状态机值(如_转换)正是我所需要的。如果为false,我将捕获它,提示用户,并将其设置为true,如果用户单击“是”,我将重试。完美的解决方案。谢谢根据您的答案用解决方案更新原始问题。再次感谢!对于未来的读者,有关如何使用Ember组件执行此操作的指南如下: