2017-08-29 50 views
0

我刚刚开始使用数据表,我正在处理数据表文档中的这个示例,但我无法获取要显示的数据。 这是.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> 

,这是arrays.txt文件:

{ 
     "data": [ 

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

的问题是,没有数据显示在数据表中。

+0

尝试将它放在'PRE'而不是表中进行调试。 'arrays.txt'好像在关闭花括号之前丢失了一个结束方括号! – neuhaus

+0

控制台上的任何错误? –

+0

@EliasSoares我得到这个:'未捕获的ReferenceError:未定义jQuery' – annie

回答

0

您在导入datatable之前jquery

由于datatable要求jQuery,您必须首先加载jQuery

此外,你不应该在头上导入脚本。在脚本标记之前将它放在身体标记的末尾。

相关问题