【问题标题】:How to display nested Json object in Jqgrid如何在 Jqgrid 中显示嵌套的 Json 对象
【发布时间】:2014-05-14 15:30:25
【问题描述】:

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

[
 {
"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 对这个问题的一些东西会非常有帮助 提前致谢

【问题讨论】:

    标签: php jquery json jqgrid


    【解决方案1】:

    您应该使用jsonMap。您还应该查看jqGrid wikithis 特定主题。你可以试试这样:

    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 中有多少条记录,并为每条记录手动完成。实际上,我不知道您如何自动实现,但正如我所说,如果您在jqGrid wiki 上寻找jsonMap,您可能会找到您想要的。祝你好运!

    【讨论】:

    • 我尝试使用它但不适合我因为我找不到具有这种特殊格式 jsonReader 的 json 的解决方案:{ repeatitems: true, root: "children" }
    • 感谢 lucasdc 令人惊讶的是,这是我现在正在使用的类似方法(在发布问题之前)但是这种方法只会给出一组值,我收到的 json 中会有多个值,这意味着“children.0.properties.client”中的 0 值往往会发生变化,我必须合并当前正在使用的多个字段.children.0.properties.client +rowObject.children.0.properties。输入}
    • 在这种情况下,'0' 也无法识别,这进一步增加了我的麻烦我希望我能够解释这个问题:(希望你能帮助我
    • 我无法理解。您的意思是“其中会有多个值,这意味着“children.0.properties.client”中的 0 值往往会改变”?这意味着“属性”不会总是在数组的索引 0 处?看看这个,告诉我这是否对你有帮助
    • 下面给出的是我正在谈论的确切 json 结构,因为它太长了我将它添加为 2 cmets 请结合它以了解确切的 json [ { "children": [ { "children ": null, "objectId": "1", "objectType": "forms", "properties": { "objectId": 1, "other": [ null ], "sponsor": null } },
    猜你喜欢
    • 2015-10-27
    • 2019-07-12
    • 1970-01-01
    • 2019-10-24
    • 1970-01-01
    • 1970-01-01
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多