簡體   English   中英

Bootstrap 對話框渲染后置

[英]Bootstrap dialog rendering postpode

我遇到了Bootstrap Dialog 的一個非常奇怪的行為出於某種原因,在下面提供的foo函數中,對話框沒有立即顯示出來。 渲染延遲到到達行$.get(... . 任何想法為什么會發生這種情況?

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

更新受 Maximus 的 anwser 的啟發,我選擇了以下對我有用的解決方法。 然而,這不是一個干凈的解決方案,因為即使它變得毫無意義,我也必須繼續循環。

function = foo()
    {
       var bad_condition_flg = false;
       $rows.each(function (i, row) 
       {
           var $row = $(row);
           if (something_is_wrong()) 
           {
               bad_condition_flg = true;
           }
           // Some other code           
        });
        if (bad_condition_flg);
        {
           alert_errr(...);  
           return;
         }
     }

為了顯示對話框,瀏覽器必須執行重繪。 僅當調用堆棧中沒有任何內容時才可能進行重繪。 因此,只有在foo完成執行后才會顯示對話框。 使用調試器時有點不同,因為有時在斷點處停止會為瀏覽器提供重新繪制的時間,並且對話框可能會在調用堆棧為空之前顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM