gpt4 book ai didi

javascript - 在 jquery 警报内容中循环

转载 作者:行者123 更新时间:2023-11-30 10:57:33 25 4
gpt4 key购买 nike

是否可以在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com