简体   繁体   English

如何在JQuery中填充复杂的JSON格式数据表

[英]How to Populate a Complex JSON format DataTable in JQuery

MY JSON Format: 我的JSON格式:

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

My jQuery Function is as follows. 我的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',},
        ],
    });
}

Here the return "'"+oObj.aData.Tower1[0].Core+"'"; 这里return "'"+oObj.aData.Tower1[0].Core+"'"; doesn't return anything. 不返回任何东西。

SOLUTION

Use the following code instead: 请使用以下代码:

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'}
        ]
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM