javascript - 在 jquery 警报内容中循环

标签 javascript jquery

是否可以在 jquery alert 的内容中添加一个循环?我想在我的表格中显示它。

  success: function (result) {
   var resultData = JSON.parse(result.data);
         if (resultData.length > 0) {
    $.alert({
      title: 'You Have Memo Notification',
      content: '<table class="table table-sm table-condensed table-hovered table-bordered mt-2">' +
             '<thead class="table-primary"><tr><td>Memo</td></thead>' +
             '<tbody>'    +                          
             '<tr><td> ' + resultData[i].MemoToFileRemarks + '  </td></tr>' +                             
             '</tbody></table>'
            });                
                  }
        }

//我想在我的 jquery alert 内容中添加这个

for (i = 0; i < resultData.length; i++) {

                       }

最佳答案

您可以考虑在发出警报之前构建您的结果,以避免为每个单独的结果执行单独警报的开销:

success: function (result) {
    var resultData = JSON.parse(result.data),
        resultContent = '';

    // If you have results, then issue an alert
    if (resultData.length > 0) {
        // Build your results
        for (i = 0; i < resultData.length; i++) {
            resultContent += '<tr><td>' + resultData[i].MemoToFileRemarks + '</td></tr>'; 
        }

        // Issue your alert
        $.alert({
            title: 'You Have Memo Notification',
            content: 
              '<table class="table table-sm table-condensed table-hovered table-bordered mt-2">' +
                '<thead class="table-primary"><tr><td>Memo</td></thead>' +
                '<tbody>' +                          
                    resultContent +                        
                '</tbody>' +
              '</table>'
        });                
    }
}

关于javascript - 在 jquery 警报内容中循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59386086/

相关文章:

javascript - 检测鼠标滚轮滚动的次数

jQuery 选择器问题

javascript - 如何选择带有列表项的偶数行

javascript - 如何在不需要时停止函数多次运行?

jquery - 等待 jQueryanimation 在 for 循环内完成

php - 检测 Firefox 插件吗?

javascript - Angular 路由: Replacing components

javascript - 如何用 jquery 或替代方法隐藏一个 div?

javascript - 如何使用 jQuery 从 HTML 中的隐藏字段获取文本

javascript - jQuery根据节的索引滚动到节