jqGrid和JSON数组 [英] jqGrid and JSON array

查看:164
本文介绍了jqGrid和JSON数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jqGrid加载以下json字符串.我想在网格中显示json,其中一列用于"id",一列用于连接myarray的所有内容,一列用于"num".我该怎么做呢?我已经尝试了一段时间了.

I would like to use jqGrid to load the following json string. I would like to display the json in a grid with one column for 'id', one column for all the contents of myarray concatenated and one column for 'num'. How do I do this? I have been trying for a while now.

{
    "id": 6,
    "urls": [
        {
            "id": 1,
            "url": {
                "myarray": [
                    "array1",
                    "array2",
                    "array3",
                    "array4",
                    "array5",
                    "array6"
                ],
                "num": 471
            }
        }
    ]
}

推荐答案

所有看起来都不像看起来那么困难.

All could be not so difficult like it looks like.

该演示显示以下网格

并使用以下代码

$("#list").jqGrid({
    url: 'iphonedevnoob.json',
    datatype: 'json',
    colModel: [
        { name:'id', width:50, formatter:'int', align:'center' },
        { name:'myarray', width:250, jsonmap:"url.myarray",
          formatter: function (cellvalue) {
              return cellvalue.join(",");
          }
        },
        { name:'num', width: 50, formatter:'int', jsonmap:"url.num", align:'center' }
    ],
    sortname: 'id',
    jsonReader: {
        page: function (obj) { return 1; },
        total: function (obj) { return 1; },
        records: function (obj) { return obj.urls.length; },
        root: 'urls',
        repeatitems: false
    },
    rowNum: 10000,   // no paging
    gridview:true,
    viewrecords: true,
    rownumbers: true,
    height: "100%",
    pager: '#pager'
});

这篇关于jqGrid和JSON数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆