Bootstrap 5用Ajax加载

发布于 2025-02-13 03:16:29 字数 1579 浏览 1 评论 0原文

我正在尝试通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文