【问题标题】:Just another jqGrid that won't display JSON data只是另一个不会显示 JSON 数据的 jqGrid
【发布时间】:2012-07-24 03:22:51
【问题描述】:

我使用 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"
    }
});

data.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
    }
}]
}

【问题讨论】:

    标签: jquery json jqgrid


    【解决方案1】:

    我使用 $.map 方法做过类似的事情。这是我的 AJAX POST 的 sn-p,它接收映射到“项目”的 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
                        }
                    }));
                },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多