可以在Bootstrap表中获取选定的行

发布于 2025-02-03 00:20:37 字数 2110 浏览 3 评论 0 原文

我已经在我的ASP.NET网页中定义了以下引导表:

<table class="display table table-bordered" data-click-to-select="true" 
                    data-pagination="true" data-sortable="true" data-show-refresh="true" data-single-select="true" data-maintain-selected="true"
                    data-show-toggle="true" data-id-field="customer_id" id="customers" name="customers">
                    <thead>
                        <tr>
                            <th data-field="state" data-checkbox="true"></th>
                            <th data-field="Customer_ID" data-sortable="true">Acct. #</th>
                            <th data-field="Company_Name" data-sortable="true">Company</th>
                            <th data-field="Federal_EIN" data-sortable="true">EIN</th>
                            <th data-field="City" data-sortable="true">City</th>
                            <th data-field="State" data-sortable="true">State</th>
                            <th data-field="Creation_Date" data-sortable="true">Added</th>
                        </tr>
                    </thead>
                </table>

并且,在此上下示例代码之后,我尝试使用以下jQuery/javascript代码来获取和显示来自选定的行的信息:

            $('#customers').on('check.bs.table', function (e, row) {
                checkedRows.push({ id: row.id, name: row.name, forks: row.forks });
                console.log(checkedRows);
                $.each(checkedRows, function (index, value) {
                    $(console.log(value.id + " | " + value.name + " | " + value.forks));
                });
            });

            $('#customers').on('uncheck.bs.table', function (e, row) {
                $.each(checkedRows, function (index, value) {
                    if (value.id === row.id) {
                        checkedRows.splice(index, 1);
                    }
                });
                console.log(checkedRows);
            });

问题是,问题是控制台。将检查行的值显示为 undefined 。我在做什么错?

I have defined the following bootstrap table in my ASP.NET web page:

<table class="display table table-bordered" data-click-to-select="true" 
                    data-pagination="true" data-sortable="true" data-show-refresh="true" data-single-select="true" data-maintain-selected="true"
                    data-show-toggle="true" data-id-field="customer_id" id="customers" name="customers">
                    <thead>
                        <tr>
                            <th data-field="state" data-checkbox="true"></th>
                            <th data-field="Customer_ID" data-sortable="true">Acct. #</th>
                            <th data-field="Company_Name" data-sortable="true">Company</th>
                            <th data-field="Federal_EIN" data-sortable="true">EIN</th>
                            <th data-field="City" data-sortable="true">City</th>
                            <th data-field="State" data-sortable="true">State</th>
                            <th data-field="Creation_Date" data-sortable="true">Added</th>
                        </tr>
                    </thead>
                </table>

And, following sample code on SO, I am trying to use the following jQuery/JavaScript code to fetch and display info from the selected row:

            $('#customers').on('check.bs.table', function (e, row) {
                checkedRows.push({ id: row.id, name: row.name, forks: row.forks });
                console.log(checkedRows);
                $.each(checkedRows, function (index, value) {
                    $(console.log(value.id + " | " + value.name + " | " + value.forks));
                });
            });

            $('#customers').on('uncheck.bs.table', function (e, row) {
                $.each(checkedRows, function (index, value) {
                    if (value.id === row.id) {
                        checkedRows.splice(index, 1);
                    }
                });
                console.log(checkedRows);
            });

The problem is, the console shows the values of the checked row as undefined. What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阪姬 2025-02-10 00:20:37

因此,我发现问题是,对象的字段对细胞敏感性,基于该表格的字段(尽管有趣的是,Bootstrap表不在乎 Data-Field 参数可观察病例敏感性!)。因此,一旦我使用适当的情况敏感性来参考 row 的字段,一切都会显示出来。
谢谢大家的帮助!

So, I figured out that the issue is, the row object's fields are case-sensitive, based on the fields the table is populated with (although interestingly, the bootstrap table doesn't care if the data-field parameters observe case-sensitivity!). So, once I used the proper case sensitivity in referring to the fields of the row, everything showed up.
Thank you everyone for your help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文