【问题标题】:Bootstrap-Table - Load json file with a linkBootstrap-Table - 加载带有链接的 json 文件
【发布时间】:2015-11-03 16:01:24
【问题描述】:

我有一个使用插件 bootstrap-table 加载了默认 json 文件的表。

这是html代码:

<p><a href="#">This link load another json file in the table, for example data-table-alert2.json</a></p>
<table id="table-alert1" class="table table-striped" data-sort-order="desc" data-sort-name="field3">
   <thead>
        <tr>
            <th>Field1</th>
            <th>Field2</th>
            <th data-field="field3" data-sortable="true">Field3</th>
            <th data-field="field4" data-sortable="true">Field4<br />de Alerta</th>
            <th data-field="field5" data-sortable="true">Field5</th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th>Field6</th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th>Field7</th>
            <th>Field8</th>
        </tr>
    </thead>                        
</table>

这是js代码:

$(document).ready(function() {
    $("#table-alert1").bootstrapTable({ 
        url: 'json/data-table-alert1.json',
        columns: [{
            field: 'col1'
        }, {
            field: 'col2'
        }, {
            field: 'col3'
        }, {
            field: 'col4'
        }, {
            field: 'col5'
        }, {
            field: 'col6'
        }, {
            field: 'col7'
        }, {
            field: 'col8'
        }, {
            field: 'col9'   
        }, {
            field: 'col10'  
        }, {
            field: 'col11'  
        }, {
            field: 'col12'  
        }, {
            field: 'col13'  
        }, {
            field: 'col14'  
        }, {
            field: 'col15'  
        }, {
            field: 'col16'          
        }, ]
    });
});

我需要当我点击一个链接或按钮时,加载另一个文件 json。

谢谢和最好的问候,

【问题讨论】:

    标签: twitter-bootstrap bootstrap-table


    【解决方案1】:

    你可以使用refresh方法做你想做的事:

    $('#link').click(function () {
        $table.bootstrapTable('refresh', {
            url: 'data-table-alert2.json'
        });
    });
    

    这里是一个例子:http://issues.wenzhixin.net.cn/bootstrap-table/#issues/409.html,来源在GitHub

    顺便说一句:你可以在https://github.com/wenzhixin/bootstrap-table/issues/409 讨论这个问题。

    【讨论】:

      【解决方案2】:

      我的回答是: 首先,Json 根本无效。您总是需要将字符串作为参数提供,例如: {“字段”:“col1”} 等等

      您可以在 jsonlint.com 网站上验证您的 JSON!

      有关更多信息,您必须等待。我现在必须离开!

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      • 2012-10-28
      • 2015-08-09
      • 1970-01-01
      • 2017-03-28
      • 2011-05-18
      相关资源
      最近更新 更多