数据表 - 嵌套数组

时间:2017-10-21 19:59:18

标签: jquery ajax datatables

我正在尝试访问'紧急情况'数组:

{"organizationUuid":1,"emergencyUuids":null,"emergencies":[{"emergencyUuid":1,"emergencyTitle":"Student Fainted in Class","pickupLocation":"1122 Fowler St. 30309","possiblePatientUuids":[1,2],"identifiedPatientUuid":null,"emergencyState":"PENDING"},{"emergencyUuid":2,"emergencyTitle":"Car Accident on I85","pickupLocation":"I85 between exits 89 and 91","possiblePatientUuids":[3,4],"identifiedPatientUuid":null,"emergencyState":"PENDING"},{"emergencyUuid":3,"emergencyTitle":"Man had Heart Attack in Restaurant","pickupLocation":"Subway on Georgia Tech Campus","possiblePatientUuids":[5,6],"identifiedPatientUuid":null,"emergencyState":"ACTIVE"},{"emergencyUuid":4,"emergencyTitle":"Dog bit Man in Neighborhood","pickupLocation":"2022 Happy Hills 30456","possiblePatientUuids":[7,8],"identifiedPatientUuid":null,"emergencyState":"CLOSED"},{"emergencyUuid":5,"emergencyTitle":"Alcohol Poisoning at PIKE Fraternity","pickupLocation":"3212 Notso Happy Hills 30213","possiblePatientUuids":[9,10],"identifiedPatientUuid":null,"emergencyState":"CLOSED"}]}

使用以下AJAX:

var table = $('#emergenciesTable').DataTable({
    "sAjaxSource": "/api/organization/"+token+"?verbose=true",
    "sAjaxDataProp": "",
    "order": [[ 0, "asc" ]],
    "aoColumns": [
        { "mData": "emergencies.emergencyTitle" },
        { "mData": "emergencies.pickupLocation" },
        { "mData": "emergencies.emergencyState" }
    ]
})

然而,没有任何东西呈现。我在控制台中看不到任何错误。

知道我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

sAjaxDataProp设置为指向emergencies数组:

var table = $('#emergenciesTable').DataTable({
    "sAjaxSource": "/api/organization/"+token+"?verbose=true",
    "sAjaxDataProp": "emergencies",
    "order": [[ 0, "asc" ]],
    "aoColumns": [
        { "mData": "emergencyTitle" },
        { "mData": "pickupLocation" },
        { "mData": "emergencyState" }
    ]
})

然后它有效 - >的 http://jsfiddle.net/Lbx49x99/

我不知道你正在使用什么版本,但有一天被弃用的sAjaxSource概念被落实了。从1.10.x开始,语法为

ajax: {
  url: "/api/organization/"+token+"?verbose=true",
  dataSrc: 'emergencies'
}