简体   繁体   English

如何在数据表中显示数据?

[英]How to display data in datatable?

I have just gotten started with datatables and I was working with this example from the datatables docs, but I can't get the data to display . 我刚刚开始使用数据表,并且正在使用datatables文档中的示例,但是我无法显示数据。 This is the .html file : 这是.html file

<html>
<head>
<title>data</title>
<script   href="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script   href="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<body>
<table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
</table>
<script type="text/javascript">
    $(document).ready(function() {
$('#example').DataTable( {
    "ajax": 'arrays.txt'
} );
} );
    </script>
</body>
</html>

and this is the arrays.txt file: 这是arrays.txt文件:

    {
      "data": [

    [
      "Tiger Nixon",
      "System Architect",
      "Edinburgh",
      "5421",
      "2011/04/25",
      "$320,800"
    ]
]
}

The problem is that no data is displayed in the datatable. 问题是数据表中没有显示任何数据。

You are importing datatable before jquery . 要导入datatable之前jquery

Since datatable requires jQuery , you must load jQuery first. 由于datatable需要jQuery ,因此必须首先加载jQuery

Also you should never import scripts on head. 另外,您绝对不要导入脚本。 Put it on the end of your body tag, before the script tags. 将其放在脚本标记之前的body标记的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM