DataTables - 从预定义的JSON加载数据

时间:2017-07-26 03:35:00

标签: arrays json datatables

我有一个问题,将dataTable指向JSON中的正确位置。我收到一个嵌套数组:

_accessoryList = [[NSMutableArray alloc] initWithArray:[[EAAccessoryManager sharedAccessoryManager] connectedAccessories]];

}

我如何指出"案例"宾语?我确信这很简单,但我对dataTables配置中的许多选项感到困惑。

我尝试过各种数据,dataSrc以及data.cases或只是案例等。 感谢

{
"status": "ok",
"count": "7",
"msg ": "Operation Successful",
"data": [{
    "contactHasServiceArea": true,
    "issueCategories": [{
            "id": "8",
            "description": "Finance"
        },
        {
            "id": "9",
            "description": "Housing"
        },
        {
            "id": "10",
            "description": "International"
        }
    ],
    "cases": [{
        "id": 31645,
        "client_name": "Matthew",
        "issue": "Assessment Completion",
        "referral": null,
        "opened_date": "10\/07\/2017",
        "case_status": "Open"
    }, {
        "id": 31668,
        "client_name": "Fanky ",
        "issue": "Complex",
        "referral": null,
        "opened_date": "01\/07\/2017",
        "case_status": "Open"
    }]
}]

1 个答案:

答案 0 :(得分:1)

您可以这样配置:

$('#cases_table').DataTable( {
  "ajax": {
     "url": "ajax/getCases",
     "dataSrc"   : "data.cases"
   },
   "columns": [
       { "data": "client_name" },
       { "data": "issue" },
       { "data": "referral" },
       { "data": "opened_date" },
       { "data": "case_status" }
    ]
  } );

datasrc指向返回json。删除数据选项。