EmberJS: reject an upcoming transition
我如何通过willTransition拒绝即将到来的转换,但是使用自定义弹出窗口或jQuery .dialog框如下:
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" );
}
}
});
}
}
答案 0 :(得分:0)
您可以使用相同的方法为路线转换设置动画:您可以查看the relatebase blog(以及博客引用的jsbin example)。
基本上你在willTransition
动作中处理一个小状态机:你中止原始转换,一旦用户关闭对话框,你就会重试原始转换。
希望它有所帮助!