我的JSON数据看起来像这样,我试图通过数据表发送它。
{
"RANDOM-UNIQUE-STRING-1":
{
"column1": "stuff",
"column2": "more stuff",
"column3": "example"
},
"RANDOM-UNIQUE-STRING-2":
{
"column1": "stuff",
"column2": "more stuff",
"column3": "example"
},
{ ... }
}
我无法弄清楚如何看待传递RANDOM-UNIQUE-STRING-1
等并直接获取数据。这就是我到目前为止所拥有的。有人认为他们可以帮忙吗?
var theTable = $('#mytable').dataTable({
"bProcessing": true,
"aaData": data, //data == my above JSON object
"aoColumns": [
{ "mData": "column1" },
{ "mData": "column2" },
{ "mData": "column3" }
]
});
答案 0 :(得分:0)
你可以制作一个"规范化" JSON。像这样:
function normalize(data) {
var result = [];
for (var row in data) {
result.push(data[row]);
}
return result;
}
然后在dataTables初始化中调用该函数:
var theTable = $('#mytable').dataTable({
aaData: normalize(data),
aoColumns: [
{ mData: "column1" },
{ mData: "column2" },
{ mData: "column3" }
]
});
演示 - >的 http://jsfiddle.net/o27hgzjr/ 强>