将JSON数据添加到datatable

时间:2014-01-19 01:20:11

标签: jquery json jquery-datatables

我想将JSON数据添加到现有数据表中。

JSON数据如下所示:

[
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"],
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"],
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"],
    ["Trident","Internet Explorer 4.0","Win 95+","4","X","X"]
]

我试过了:

$('#' + tab + '_table').dataTable().fnAddData(data);

data持有JSON数据。

因为它只添加了一行,所以似乎有任何错误:

enter image description here

1 个答案:

答案 0 :(得分:5)

看起来您要求dataTables将原始JSON数据添加到您的表中。您应首先使用JSON.parse()解析它并添加生成的Javascript数组。

var jsdata = JSON.parse(data);
$('#' + tab + '_table').dataTable().fnAddData(jsdata);