jQuery Datatables“表中没有数据”json

时间:2016-04-06 06:48:12

标签: jquery json datatable

我正在努力解决“DataTables中没有数据可用”的问题。我的问题是我有一个服务器端发送的Json数组,我得到了响应,但是DataTable无法读取它所以我不知道我知道如何解决这个问题。

所以这是我的代码。

var table = $('#opportunities').DataTable({
    "processing": true,
    "ajax": {
        "url": 'api/opportunities/article/' + id,
        "type": "GET",
        "dataSrc": ""
    },
    "columns": [{
            "data": "name"
        }, {
            "data": "status"
        }, {
            "data": "eval.4"
        }, {
            "data": "eval.3"
        }, {
            "data": "articleName"
        }]
});

这是来自服务器的json响应

{
    "85": {
        "id": 85,
        "idArticle": 109,
        "articleName": "pozjdpoo",
        "status": "baseline",
        "name": "blabla for test",
        "responsable": "blabla for test",
        "description": "",
        "credibilite": 0.0,
        "commentaires": "",
        "link": "",
        "PJ": null,
        "affectedArticle": null,
        "eval": {
            "id": 52,
            "opp": 85,
            "coeff": null,
            "score": null
        }
    },
    "56": {
        "id": 56,
        "idArticle": 109,
        "articleName": "pozjdpoo",
        "status": "Initial",
        "name": "report",
        "responsable": "report",
        "description": null,
        "credibilite": 0.0,
        "commentaires": null,
        "link": null,
        "PJ": null,
        "affectedArticle": null,
        "eval": null
    }
}

然后在我的页面上,在我的表格行中,我没有数据可用消息

结果:http://i.stack.imgur.com/DbFDJ.png

1 个答案:

答案 0 :(得分:0)

您的json响应格式应如下所示:

{"recordsTotal":"##number of total results",
 "recordsFiltered":"##number of filtered results(if any filter like search is applied)",
 "data":[
          ["##name1","##status1","##eval.41","##eval.31","##articleName1"],
          ["##name2","##status2","##eval.42","##eval.32","##articleName2"],
        ]
}

其中## name1,## status1是相应的值。