javascript - 当我提供的 JSON 看起来有效时,数据表返回表中没有可用数据

标签 javascript jquery ajax json datatable

我正在尝试初始化数据表并为其提供一个对象数组。我收到一条错误消息,指出表中没有可用数据。但我可以将其打印到控制台并发现这是不正确的。

//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/

相关文章:

javascript - 更新按钮 ID

javascript - 正确显示 ajax 请求到 html 的结果

javascript - D3.js .rangeBands() 返回 'undefined' 仅包含最后一个值?

jQuery - 从 HTML 字符串中获取 HTML

javascript - 在正文中搜索关键字

javascript - 如何访问 jstree 排序函数中的节点数据属性?

c# - 在 Azure 中发布时 Web 应用程序行为不同

jquery - PhoneGap 1.5.0 Android Cordova AJAX JSON

javascript - 根据它包含的表更改 div 高度

javascript - jQuery 中的 PHP (WordPress)