dynatable无法从远程JSON创建表 [英] dynatable not creating table from remote JSON
问题描述
在这里,feature-table.JSON与HTML文件位于同一目录中:
Here's feature-table.JSON in the same directory as the HTML file:
[
{
"band": "Weezer",
"song": "El Scorcho"
},
{
"band": "Chevelle",
"song": "Family System"
}
]
这是我的HTML文件:
Here's my HTML file:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.11.1.min.js">
<script type="text/javascript" src="jquery.dynatable.js"></script>
<script type="text/javascript">
$.getJSON("feature-table.JSON", function(data) {
alert(data);
$("#feature-table").dynatable({
dataset: {
records: data
}
});
});
</script>
</head>
<body>
<table id="feature-table">
<thead>
<th>band</th>
<th>song</th>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
该警报会弹出正确的JSON数据,因此我知道它已找到它.我尝试过:jQuery 2,上载并使用js文件的URL,以确保文件位于正确的位置,$.ajax,然后在读取
The alert pops up with the correct JSON data so i know it's finding it. I've tried: version 2 of jQuery, uploading and using URLs of the js files to make sure the files are in the right place, $.ajax but then $.getJSON after reading Load remote JSON from Dynatable, and various other things. I'm out of ideas. What am I overlooking?
推荐答案
我发现我需要在$(document).ready(function(){...})
中包含我的JavaScript.
I discovered I needed to have my JavaScript inside $(document).ready(function(){...})
.
这篇关于dynatable无法从远程JSON创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!