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

Bootstrap Example: Loading data from JSON into a table

本文关键字:加载 JSON 示例 数据 Bootstrap      更新时间:2023-09-26

我试图在这里遵循这个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>

Bootstrap不支持您想要使用的表功能。你必须包括引导表。否则它就不会起作用。下载Bootstrap表并在代码中使用它。http://bootstrap-table.wenzhixin.net.cn/getting-started

答案很晚,但以防万一有人遇到这个问题。使用类似ajax的请求的问题之一是需要一个服务器。实际上,任何服务器都可以这样做,但您无法让它在普通文件系统上工作。