【问题标题】:Bootstrap table get data from selected row引导表从选定行获取数据
【发布时间】:2019-01-29 10:45:51
【问题描述】:

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

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

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

bootstraptable('getselections')

但我收到了这个

getSelections: [对象对象]

除了这个

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>

【问题讨论】:

  • getSelections[0] 能给你什么?由于您正在警报中打印,因此它会提供这样的输出。就做console.log('getSelections: ', $("#table").bootstrapTable('getSelections'))
  • @SujataChanda 我收到此消息:getSelections: w.fn.init [table#table]

标签: javascript php bootstrap-table


【解决方案1】:

参考Bootstrap Table getSelections example

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

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

【讨论】:

  • 抱歉,我不使用 JSON 作为数据 URL 来填充我的表格
  • 如果我这样做,我会收到:`getSelections: {"0":{"jQuery331073420158381058982":{"width":600,"height":600,"showColumns":true}," jQuery331073420158381058981":{"hasDataAttrs":true}},"length":1} `
  • 嗯..请出示您的bootstrap-table.js文件的getSelections方法代码。
  • `BootstrapTable.prototype.getSelections = function () { var that = this; return $.grep(this.options.data, function (row) { // 修复 #2424: from html with checkbox return row[that.header.stateField] === true; }); }; `
猜你喜欢
  • 2022-06-01
  • 1970-01-01
  • 2020-02-15
  • 2016-11-25
  • 2012-08-09
  • 1970-01-01
  • 2012-10-02
  • 2021-12-20
  • 1970-01-01
相关资源
最近更新 更多