JSON 数据表来源

JSON source to datatables

我有这个代码:

testdata = [{
    "hasresults": true,
    "resultscount": 5,
    "dob": null,
    "chart": {
        "rows": [
            {
                "chart": "BAR000",
                "firstname": "RUSSELL",
                "lastname": "BARON"
            },
            {
                "chart": "BAR001",
                "firstname": "BRUSELL",
                "lastname": "BARON"
            },
            {
                "chart": "BAR002",
                "firstname": "GARY",
                "lastname": "BARON"
            }
        ]
    }
}];

$('#test').dataTable({
    "aaData": testdata,
        "aoColumns": [{
        "mDataProp": "chart"
    }, {
        "mDataProp": "firstname"
    }, {
        "mDataProp": "lastname"
    }]
});

谁能帮我看看为什么这不起作用?似乎如果我删除以下内容,它将起作用:

"hasresults": true,
"resultscount": 5,
"dob": null,
"chart": {

Not working fiddle

Working fiddle

您只需要以正确的方式解决 testdatatestdata 是一个包含一个对象的数组,该对象有另一个对象 chart,包含一个数组 rows.

$('#test').dataTable({
    "aaData": testdata[0].chart.rows, //<------
    "aoColumns": [{
        "mDataProp": "chart"
    }, {
        "mDataProp": "firstname"
    }, {
        "mDataProp": "lastname"
    }]
});

你的代码在这里工作 -> http://jsfiddle.net/j1fvL96e/