如何在Jqgrid中显示嵌套的Json对象 [英] How to display nested Json object in Jqgrid

查看:135
本文介绍了如何在Jqgrid中显示嵌套的Json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jqgrid相当陌生 如何在jqgrid中将嵌套的json对象显示为单个字段? 下面给出的是json对象的示例

I'm fairly new to jqgrid How can I show nested json objects inside a jqgrid as individual fields?? below given is the example of json object

[
 {
"properties":{
 "x":1,
 "y":78093,
 "closeDate":null,
 "
},
"children":[
 {
    "properties":{

       "option":null,
       "type":"",
       "client":"southface",

       "categoryA":[
          "x",
          "w"
       ],
       "facilitiesOther":null,
       "objectId":10,

       "docNo":7897,
       "Provisions":[
          "x",
          "z"
       ],


       "sponsor":"own sponsor",


       "CategoryB":[
          "e",
          "f",
          "g"

       ]

       ]
    },
    "children":null,
    "Type":"test",
    "Id":"10"
 }
  ],
  "objectType":"document",
 "objectId":"89763"
   }
  ]

经过大量研究,我发现它需要修改colmodel 解决这个问题会很有帮助 预先感谢

after fair amount of research I found somewhere that it requires modifying the colmodel Something towards this issue would be very helpful thanks in advance

推荐答案

您应使用jsonMap.您还应该查看 jqGrid Wiki

You should use jsonMap. You should also look at jqGrid wiki and this specific topic. You can try something like this:

colNames:['Children','ID', 'Properties', 'Other','Sponsor'],
colModel: [
    {name:'children',width:100, jsonmap:"children.0", formatter: function (cellvalue) { return cellvalue.children }},
    {name:'objectId',width:100, jsonmap:"children.0", formatter: function (cellvalue) { return cellvalue.objectType }},
    {name:'properties',width:100, jsonmap:"children.0", formatter: function (cellvalue) { return cellvalue.properties.objectId }},
    {name:'other',width:100, jsonmap:"children.0", formatter: function (cellvalue) { return cellvalue.properties.other[0] }},
    {name:'sponsor',width:100, jsonmap:"children.0", formatter: function (cellvalue) { return cellvalue.properties.sponsor }}
    // and so on...
],

这显然不是最好的方法,因为您必须知道JSON上有多少条记录,并为每条记录手动进行.实际上,我不知道如何自动实现它,但是正如我所说,如果您在

This is obviously not the best approach because you'll have to know how many records you have on your JSON and do it manually for each one. Actually, I don't know how you could make it automatically, but as I said, if you look out for jsonMap on jqGrid wiki you'll probably find what you want. Best of luck!

这篇关于如何在Jqgrid中显示嵌套的Json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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