0

我使用 jqGrid 来显示表格。如果数据是local,它可以正常工作,但如果它以 JSON 形式给出,则不会显示数据。

我搜索了很多,但没有一个可以解释我的问题。这里有什么建议吗?

Javascript:

    jQuery("#gpaTable").jqGrid({
    url: "data.html",
    datatype: "json",
    pager: "#gpaPager",
    height: "100%",
    colNames: [
        "star",
        "id",
        "name",
        "gpa",
        "tag",
        "failCnt",
        "lowScore",
        "noScore"],
    colModel: [{
        name: "star",
        index: "star",
        width: 20
    },
    {
        name: "id",
        index: "id",
        width: 80
    },
    {
        name: "name",
        index: "name",
        width: 80
    },
    {
        name: "gpa",
        index: "gpa",
        width: 40,
        sorttype: "float"
    },
    {
        name: "noScore",
        index: "noScore",
        width: 80,
        sorttype: "int"
    },
    {
        name: "lowScore",
        index: "lowScore",
        width: 80,
        sorttype: "int"
    },
    {
        name: "failCnt",
        index: "failCnt",
        width: 60,
        sorttype: "int"
    },
    {
        name: "tag",
        index: "tag",
        width: 300
    }],
    multiselect: true,
    caption: "GPA",
    viewrecords: true,
    jsonReader: {
        repeatitems: false,
        id: "lineId",
        cell: "cell",
        root: "rows",
        records: "records",
        total: "pageTotal",
        page: "pageId"
    }
});

数据.html:

{
"total": 1,
"page": 1,
"records": 1,
"pageId": 1,
"pageTotal": 1,
"rows": [{
    "lineId": 1,
    "cell": {
        "star": "",
        "id": "5090379054",
        "name": "BBB",
        "gpa": "2.6",
        "tag": "",
        "failCnt": 2,
        "lowScore": 0,
        "noScore": 2
    }
},
{
    "lineId": 2,
    "cell": {
        "star": "",
        "id": "5090379051",
        "name": "BBB",
        "gpa": "2.1",
        "tag": "",
        "failCnt": 2,
        "lowScore": 0,
        "noScore": 2
    }
},
{
    "lineId": 3,
    "cell": {
        "star": "",
        "id": "5090379052",
        "name": "CCC",
        "gpa": "3.5",
        "tag": "<ul class='tagClass'><li>Tag3</li><li>Tag4</li><li>Tag5</li><li>Tag6</li></ul>",
        "failCnt": 0,
        "lowScore": 70,
        "noScore": 0
    }
},
{
    "lineId": 4,
    "cell": {
        "star": "<span class='ui-icon ui-icon-star' value='starred' />",
        "id": "5090379032",
        "name": "DDD",
        "gpa": "1.5",
        "tag": "",
        "failCnt": 1,
        "lowScore": 90,
        "noScore": 5
    }
},
{
    "lineId": 5,
    "cell": {
        "star": "<span class='ui-icon ui-icon-star' value='starred' />",
        "id": "5090379032",
        "name": "EEE",
        "gpa": "1.2",
        "tag": "<ul class='tagClass'><li>Tag3</li></ul>",
        "failCnt": 4,
        "lowScore": 120,
        "noScore": 2
    }
}]
}
4

1 回答 1

0

我使用 $.map 方法做了类似的事情。这是我的 AJAX POST 的一个片段,它接收一个映射到“项目”的 JSON 对象,这是我的插件所期望的一个对象,它显示接收到的数据(在我的情况下不是网格,但在概念上是相同的交易)..

  $.ajax({
            type: "POST",
            url: '/Venues/GetVenuesJSON',
            dataType: "json",
            data: JSON.stringify(jsonToSend1),
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                response($.map(data, function (item) {
                    return {
                        success: item.success,
                        label: item.label,
                        value: item.label,
                        id: item.value
                    }
                }));
            },
于 2012-07-24T03:36:55.257 回答