我正在尝试学习一些jQuery和javascript,并有一个整洁的项目可以尝试。它涉及到从JSON文件中提取数据,并基于日期以表格形式显示数据。我发现Dynatable似乎可以做我想做的事情,但我一直收到“JSON输入的意外结束”错误。我使用的语法与Dynatabe页面上给出的示例中的语法相同,但它不返回任何记录。任何帮助都将不胜感激,因为我确信我错过了一些简单的东西。JSON文件名为json-records.json
[
{
"band": "Weezer",
"song": "GA Scorcho"
},
{
"band": "Chevelle",
"song": "Family System"
},
]<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="./jspkg-archive/jquery.dynatable.js"></script>
<script src="json-records.json"></script>
<style src="./jspkg-archive/jquery.dynatable.css"></style>
</head>
<body>
<table id="my-final-table">
<thead>
<th>Band</th>
<th>Song</th>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
$(document).ready( function(){
$('#my-final-table').dynatable();
});
var $records = $('#json-records'),
myRecords = JSON.parse($records.text());
$('#my-final-table').dynatable({
dataset: {
records: myRecords
}
});
</script>
</body>
</html>
发布于 2016-08-19 07:19:30
您的JSON文件中有一个迷路的',‘
[
{
"band": "Weezer",
"song": "GA Scorcho"
},
{
"band": "Chevelle",
"song": "Family System"
}, <--- Here
]https://stackoverflow.com/questions/39028896
复制相似问题