如何在JQuery中填充复杂的JSON格式DataTable

时间:2015-08-11 08:46:34

标签: jquery json jquery-ui datatables getjson

MY JSON格式:

{
"Tower1": [
    {
        "Core": "1",
        "RadioActivity_Warning": "10",
        "RadioActivity_Critical": "80"
    },
    {
        "Core": "2",
        "RadioActivity_Warning": "10",
        "RadioActivity_Critical": "80"
    }
]
}

我的jQuery功能如下。

function LoadThresholdInformation(data) {
    $(TABLE).dataTable({
        bPaginate : false,
        bDestroy : true,
        bFilter : false,
        bInfo : false,
        sScrollY: "100%",
        sScrollX: "100%",
        bInfinite: true,
        aaData: data,
        aoColumns : [
            {fnRender: function (oObj) {
                    return "'"+oObj.aData.Tower1[0].Core+"'"; ///not working?
            }, mDataProp: 'Core', sDefaultContent: '' },
            {mDataProp: 'RadioActivity_Warning',},
            {mDataProp: 'RadioActivity_Critical',},
        ],
    });
}

此处return "'"+oObj.aData.Tower1[0].Core+"'";不会返回任何内容。

1 个答案:

答案 0 :(得分:0)

  

<强>解

请改用以下代码:

function LoadThresholdInformation(data) {
    $(TABLE).dataTable({
        bPaginate : false,
        bDestroy : true,
        bFilter : false,
        bInfo : false,
        sScrollY: "100%",
        sScrollX: "100%",
        bInfinite: true,
        aaData: data,
        aoColumns : [
            {
               mRender: function (data, type, full){
                  return "'" + data + "'";
               }, 
               mDataProp: 'Core', 
               sDefaultContent: '' 
            },
            {mDataProp: 'RadioActivity_Warning'},
            {mDataProp: 'RadioActivity_Critical'}
        ]
    });
}