我正在尝试初始化数据表并为其提供一个对象数组。我收到一条错误消息,指出表中没有可用数据
。但我可以将其打印到控制台并发现这是不正确的。
//JS
get_notes().done(funciton(){
console.log(my_json)//what its format is below
//my_json = [
{
"username": "thomas",
"fullname": "Thomas familyname"
},
/*...*/]
_.isArray(my_json) //true
$("#note_table").DataTable({
data: my_json,
columns: [
{title: "fullname"},
{title: "username"}
]
});
});
<!--HTML-->
<table id="note_table">
<thead>
<tr>
<th>fullname</th>
<th>username</th>
</thead>
<tobdy>
</tbody>
</table>
如何防止此错误?
最佳答案
你最大的问题是:
columns: [
{title: "fullname"},
{title: "username"}
]
应该是
columns: [
{data: "fullname"},
{data: "username"}
]
您还必须确保您的表已正确定义(拼写错误 <tobdy>
)
这是您的示例的工作 fiddle 的链接: http://jsfiddle.net/bmartinelle/bjppck3d/1/
关于javascript - 当我提供的 JSON 看起来有效时,数据表返回表中没有可用数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25880520/