0

文档中是直接拿json

<table data-toggle="table" data-url="data1.json">
    <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>

但是我的json格式如下

{   "code": "0",
    "data": {"messages":[{"id":1,"name":"Mark","price":"10"},....]}
}    

请问该如何修改?

查看全部 2 个回答

0

<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="bootstrap/bootstrap-table.css">
<link rel="stylesheet" type="text/css" href="bootstrap/bootstrap-table.min.css">

</head>
<body>

</body> <script type="text/javascript" src="jquery/jquery.min.js"></script> <script type="text/javascript" src="bootstrap/bootstrap.min.js"></script> <script type="text/javascript" src="bootstrap/bootstrap-table.min.js"></script> <script type="text/javascript" src="bootstrap/bootstrap-table-zh-CN.js"></script> <script type="text/javascript"> $(function () { var oTable = new TableInit(); oTable.Init(); }); var TableInit = function () { var oTableInit = new Object(); //初始化Table oTableInit.Init = function () { $('#tb_departments').bootstrapTable({ url: 'data.json', method: 'get', toolbar: '#toolbar', striped: true, cache: false, uniqueId: "id", columns: [{ field: 'id', title: 'Item ID', align:'center' }, { field: 'name', title: 'Item Name', align:'center' },{ field: 'price', title: 'Item Price', align:'center' }],responseHandler:function(data){ return data.data.messages } }); }; // //得到查询的参数 // oTableInit.queryParams = function (params) { // var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的 // limit: params.limit, //页面大小 // offset: params.offset, //页码 // departmentname: $("#txt_search_departmentname").val(), // statu: $("#txt_search_statu").val() // }; // return temp; // }; return oTableInit; } </script> </html>图片描述 [1]: /img/bVWX3l