我遇到了Bootstrap Dialog的一种非常离奇的行为
出于某种原因,在下面提供的library(gtable)
leg <- gtable_filter(ggplot_gtable(ggplot_build(p1)), "guide-box")
grid.arrange(p1 + guides(color = FALSE), p2, leg, ncol=3, widths = c(4,1,1))
函数中,对话框不会立即显示。渲染延迟到达到foo
行的那一刻。任何想法为什么会发生这种情况?
$.get(...
更新 受Maximus&#39;的启发anwser,我选择了以下为我工作的解决方法。然而,这不是一个干净的解决方案,因为即使它变得毫无意义,我也必须继续循环。
function = foo()
{
$rows.each(function (i, row)
{
var $row = $(row);
if (something_is_wrong())
{
alert_error('Something is wrong', $form, '');
return;
}
// Some other code
});
// The Bootstrap modal dialog shows up when reaching the point below !!!
$.get('/sending_order_notification/' + legal_entity_own_id, function(response)
{
BootstrapDialog.show({ ...
// ...
});
}
function alert_error(message, $current_form, function_name)
{
if ($current_form != undefined)
$current_form.modal('hide');
BootstrapDialog.show(
{
type: BootstrapDialog.TYPE_DANGER,
title: 'Ошибка',
message: message,
draggable: true,
buttons: [{
label: 'OK',
action: function(dialogItself) {
dialogItself.close();
if (function_name != undefined)
$.post('/send_error_report/', function_name);
}
}]
});
}
答案 0 :(得分:1)
为了显示对话框,浏览器必须执行重绘。只有在调用堆栈中没有任何内容时才可以重新绘制。因此,只有在foo
完成执行后才会显示对话框。使用调试器时有点不同,因为有时在断点处停止会给浏览器一些时间进行重新绘制,并且在调用堆栈为空之前可能会显示对话框。