Bootstrap 5用Ajax加载
我正在尝试通过Ajax加载bootstrap弹出窗口。弹出声似乎加载了,但是弹出窗体显示为[Object Object]
。以下是我的代码。我在悬停(链接)上触发弹出窗口。
$(".jtxndtl").popover({
delay: 500,
content: function () {
var elem = $(this);
url = elem.data('link');
return $.getJSON(url, function (data) {
var resp = data.msg;
var dtl = `<table class="border"> <tr><th>Date</th>
<th>Description</th>
<th>Payee</th>
<th>Outflow</th>
<th>Inflow</th>
</tr>`;
$.each(resp, function (key, value) {
dtl += `<tr>
<td>`+ value['event_date'] + `</td>
<td>`+ value['description'] + `</td>
<td>`+ value['payee'] + `</td>
<td>`+ value['dr_amount'] + `</td>
<td>`+ value['cr_amount'] + `</td>
</tr>`;
});
dtl += "</table>";
// console.log(dtl);
return dtl;
});
}
});
如您所见,我正在尝试在弹出窗口中加载一个格式化的表。表值在console.log(dtl)
中正确填充,但是数据在popover中未按预期显示。
我尝试了这里发布的许多解决方案(BS5很少),但似乎没有用。任何帮助将不胜感激。
I'm trying to load a Bootstrap popover via AJAX. The popover seems to load but the popover body shows as [object Object]
. Below is my code. I trigger the popover on hover (link).
$(".jtxndtl").popover({
delay: 500,
content: function () {
var elem = $(this);
url = elem.data('link');
return $.getJSON(url, function (data) {
var resp = data.msg;
var dtl = `<table class="border"> <tr><th>Date</th>
<th>Description</th>
<th>Payee</th>
<th>Outflow</th>
<th>Inflow</th>
</tr>`;
$.each(resp, function (key, value) {
dtl += `<tr>
<td>`+ value['event_date'] + `</td>
<td>`+ value['description'] + `</td>
<td>`+ value['payee'] + `</td>
<td>`+ value['dr_amount'] + `</td>
<td>`+ value['cr_amount'] + `</td>
</tr>`;
});
dtl += "</table>";
// console.log(dtl);
return dtl;
});
}
});
As you can see, I'm trying to load a formatted table in the popover. The table values populate correctly in the console.log(dtl)
but the data does not show in the popover as intended.
I tried the numerous solutions posted here (very few for BS5) but none seem to work. Any help will be highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论