javascript - 数据表不显示数据

标签 javascript datatables

您好,我有以下数据,但无法让 DataTables 显示它:

const data = [{
      "School":"Arsenal 2011",          
      "Group":{
         "Name":"Previous",             
         "ParentGroup":{
            "Name":"Arsenal",           
            "ParentGroup":{
               "Name":"USA",            
               "ParentGroup":null
            }
         }
      },
      "GroupDisplayText":null,
      "Publisher":"Abbot",
      "PublishedDate":"2011",
      "PublishersWebsite":"http://google.com/USA/ADW%202011/Arsenal%202011.pdf"
   },
   {
      "School":"New York 2000",
      "Group":{
         "Name":"New York",
         "ParentGroup":{
            "Name":"USA",
            "ParentGroup":null
         }
      },
      "GroupDisplayText":null,
      "Publisher":"DoE",
      "PublishedDate":"2000",
      "PublishersWebsite":"http://google.com/USA/New York%202000%20Tables.pdf"
   }];


    $(document).ready(function () {
          $('#example').DataTable( {
            "ajax": data
         } );
    }

我在 playcode 上创建了一个项目

https://playcode.io/470603

我收到数据表错误

DataTables 警告:表 id=example - 无效的 JSON 响应。有关此错误的更多信息,请参阅http://datatables.net/tn/1

我已经检查了 json,一切正常吗?

谢谢

最佳答案

 $(document).ready(function () {
          $('#example').DataTable( {
            data:data // ajax for to make ajax request to retrieve data.
            "columns": [ // also needs to specify column config to display it
             { "data": "School" },      
             ] 
         } );
    }

对于 javascript 对象,请使用数据。

关于javascript - 数据表不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58844619/

相关文章:

javascript - 在 jquery 中获取带有 url 值的路径名

javascript - 迭代 NodeList 并移动其元素而不转换为数组的惯用方法是什么?

javascript - Angular 自定义多选列表

javascript - 带有信息窗口的多个标记

jquery - 从文本框中删除自动搜索并在搜索按钮上搜索

jquery - 修复数据表中的多列

javascript - 有没有办法提高这个表达式的浮点精度?

javascript - 在数据表上设置自动焦点 - $.focus() 不进行更改

css - 调整标题不适用于 DataTable js

jquery - 通过单击行内的按钮访问数据表中的数据