javascript - Bootstrap 表从选定行获取数据

标签 javascript php bootstrap-table

我已经创建了一个引导表(见图)

enter image description here

此表由与 php 服务器端的 mysql 连接填充。

我的问题是从表中的选定行获取数据,我知道我必须使用函数

bootstraptable('getselections')

但是我收到了这个

getSelections: [object Object]

代替这个

getSelections: [{"Nation":"dad","Site":"-"}]

你能帮帮我吗?

完整代码在这里

<div id="toolbar">
            <button id="button" class="btn btn-default">getSelections</button>
        </div>
<table id="table" data-click-to-select="true" 
                data-toggle="table"
               data-toolbar="#toolbar"
               data-height="600"
               data-click-to-select="true" 
               data-url="db_list.php"
               data-search="true"
               data-pagination="true"
               >
            <thead>
            <tr>
                <th data-field="num"  data-checkbox="true" >#</th>
                <th data-field="Nation">Nation</th>
                <th data-field="Site">Site</th>
            </tr>
            </thead>

               </table>

<script type="text/javascript">
    var $table = $('#table'),
        $button = $('#button');

    $(function () {
        $button.click(function () {
            alert('getSelections: ' +  $("#table").bootstrapTable('getSelections'));
        });
    });
</script>

最佳答案

引用Bootstrap Table getSelections example

它使用 JSON.stringfy 函数。所以你必须使用如下。

alert('getSelections: ' + JSON.stringify($("#table").bootstrapTable('getSelections')));

关于javascript - Bootstrap 表从选定行获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51979283/

相关文章:

javascript - Vue 在路由器 View 中相同组件之间切换将不会再次安装/创建

javascript - repl Node js问题SyntaxError : Unexpected identifier

php - 从 PHP 将 MySQL 结果输出为 <table> 格式的正确方法是什么?

Ubuntu 12.04.3 x32 的 nginx VPS 上的 phpmyadmin 错误

twitter-bootstrap-3 - 如何更改 Bootstrap 表列中的列数据

javascript - 客户端和服务器端编程有什么区别?

javascript - 获取/设置状态对象(vanilla js)

php - Laravel Sail 部署就绪了吗

javascript - 无法从数据属性中提取文本

javascript - 不使用jquery在click中获取bootstrap表的行索引