Bootstrap示例:将数据从JSON加载到表中

AAA*_*AAA 2 html javascript json twitter-bootstrap

我试图在这里遵循这个Bootstrap教程,到目前为止,下面的代码如下.此代码似乎加载HTML页面确定但它不会加载.json文件中的数据,即使.json文件位于同一目录中.我将这些文件放在我的网络服务器上并通过Chrome查看页面,但仍然使用空表.控制台不显示任何内容.如何将data1.json数据显示在表中,我怎么能解决这个问题呢?

谢谢

    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <h1>Hello, world!</h1>

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

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

小智 7

Bootstrap不支持您要使用的表格功能.你必须包括Bootstrap表.否则它将无法工作.下载Bootstrap表并在您的代码中使用它. http://bootstrap-table.wenzhixin.net.cn/getting-started