使用这种特殊格式来创建JQ Grid的Json

时间:2014-02-24 21:17:55

标签: php jquery json jqgrid

我是Jquery& Json的新手,我正在尝试Jqgrid 我有一个php页面返回特定格式的json,如下所示

[{"properties":{"Name":"x","age":23,"loc":"venice"},
"Id":"422",
"Type":"bling"}]

我需要一些帮助才能将这些数据添加到网格中 我看到的所有例子都没有匹配Json的这种格式

   $("#list").jqGrid({
        url: "test.php",
        datatype: "json",
        mtype: "GET",
        colNames: ["name", "age", "Loc"],
        colModel: [
            { name: "name", width: 55 },
            { name: "age", width: 90 },
            { name: "loc", width: 80, align: "right" }

        ],
        pager: "#pager",
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: "name",
        sortorder: "desc",
        viewrecords: true,
        gridview: true,

        autoencode: true,

        caption: "test",
         jsonReader : {
        repeatitems: true,
        cell: "cell",
        id:"id",
        userdata: "userdata",
        root: "properties",
        page: "page",
        total: "total",
        records: "records"
       }  
    }); 

凭借我最低限度的理解,我猜它是关于json读者的 帮助将不胜感激

提前感谢

1 个答案:

答案 0 :(得分:1)

将您的colModel更改为

colModel: [
        { name: "properties.Name", width: 55 },
        { name: "properties.age", width: 90 },
        { name: "properties.loc", width: 80, align: "right" }

    ]