在将动态数据调用到jquery数据表时获取错误

时间:2018-05-01 11:54:32

标签: jquery datatable

在将动态数据渲染到数据表时,我收到以下错误。

错误:

jquery.dataTables.min.js:78 Uncaught TypeError: Cannot read property 'style' of undefined
    at da (jquery.dataTables.min.js:78)
    at ba (jquery.dataTables.min.js:58)
    at HTMLTableElement.<anonymous> (jquery.dataTables.min.js:127)
    at Function.each (jquery-1.8.2.min.js:2)
    at init.each (jquery-1.8.2.min.js:2)
    at init.j (jquery.dataTables.min.js:116)
    at datatable.html:16
da @ jquery.dataTables.min.js:78
ba @ jquery.dataTables.min.js:58
(anonymous) @ jquery.dataTables.min.js:127
each @ jquery-1.8.2.min.js:2
each @ jquery-1.8.2.min.js:2
j @ jquery.dataTables.min.js:116
(anonymous) @ datatable.html:16

我正在解释下面的代码。

  

datatable.html:

<html>
<head>
  <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
</head>
<body>
  <table id="example">
  <thead>
    <tr><th class="site_name">Name</th><th>Url </th><th>Type</th><th>Last modified</th></tr>
  </thead>
  <tbody>
  </tbody>
</table>
  <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
  <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
  <script>
  $("#example").dataTable({
  "bServerSide": true,
  "sAjaxSource": "http://localhost/test/data_source.json",
  "aoColumns": [{
    "mData":"name",
    "sTitle": "Site name"
  },{
    "mData": "url",
    "mRender": function ( url, type, full )  {
      return  '<a href="'+url+'">' + url + '</a>';
    }
  },{
    "mData": "editor.name"
  },{
    "mData": "editor.phone"
  },{
    "mData":"editor",
    "mRender": function(data){
      return data.email.join("<br>");
    }
  }]
});
  </script>
</body>
</html>
  

data_source.json:

{ 
    "iTotalRecords": 50,
    "iTotalDisplayRecords": 10,
    "sEcho":10,
    "aaData": [
        {"name": "Sitepoint", "url": "http://sitepoint.com", "editor" :{ "name" : "John Doe", "phone" : ["9191919", "1212121"], "email":[]}},
        {"name": "Flippa", "url": "http://flippa.com",  "editor": { "name": "Adam Smith", "email" : ["adam.smith@domain.com"], "phone":[] }}
    ]
}

这里我试图获取数据rom .json文件并在表上呈现这些记录,但在浏览器控制台中收到上述错误。我需要解决这个问题。

0 个答案:

没有答案