【问题标题】:How to Populate a Complex JSON format DataTable in JQuery如何在 JQuery 中填充复杂的 JSON 格式数据表
【发布时间】:2015-08-11 08:46:34
【问题描述】:

我的 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+"'"; 不返回任何内容。

【问题讨论】:

  • 你需要先解析它!
  • 解析后也不工作。

标签: jquery json jquery-ui datatables getjson


【解决方案1】:

解决方案

请改用以下代码:

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

【讨论】:

    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    相关资源
    最近更新 更多