我还没有找到如何在bootstrap表中插入和更新数据的确切答案.
数据来自JSON格式的URL.
我必须在同一个表中使用多个URL.
解决方法
<html> <head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.8.1/bootstrap-table.css"> <!-- Latest compiled and minified JavaScript --> <script src="js/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.8.1/bootstrap-table.js"></script> </head> <body> <div style="margin : 100px;"> <button class="btn-primary btn" onclick="load();" >Load Table</button> <button class="btn-primary btn" onclick="reload();">Update Table</button> </div> <table class="table" id="table"> <thead> <tr> <th data-field="id">Item ID</th> <th data-field="name">Item Name</th> <th data-field="price">Item Price</th> </tr> </thead> </table> <script> $('#table').bootstrapTable({}); function load(){ var data = [{ id: 1,name: 'Item 1',price: '$1' },{ id: 2,name: 'Item 2',price: '$4' }]; $('#table').bootstrapTable("load",data); } function reload(){ var data = [{ id: 3,name: 'Item 3',price: '$2' },{ id: 4,name: 'Item 4',price: '$6' }]; $('#table').bootstrapTable("load",data); } </script> </body> </html>
如果数据来自API作为JSON,您需要首先从API端点下载JSON并将其存储在javascript变量中并加载