【问题标题】:How to map a json response that has both dot in the field name and has a value sub element如何映射在字段名称中同时具有点且具有值子元素的 json 响应
【发布时间】:2019-06-07 21:51:21
【问题描述】:

我有一个如下所示的 JSON:

{"resolution": [
      {
      "resolution.resolution_id": {"val": "28"},
      "resolution.resolution_comment": {"val": "sdfsdfsdfsdfs"},      
      "resolution.resolved_by_user": {"val": "XXX"}

   },
      {
      "resolution.resolution_id": {"val": "28"},
      "resolution.resolution_comment": {"val": "sdfsdfsdfsdfs"},
      "resolution.resolved_by_user": {"val": "YYY"}
   }
]}

和一个 JQGrid 定义:

$(newTable).jqGrid({
            url:"someurl",
            mtype: 'GET',
            datatype: "json",
            height: 250,
            colNames:['id'],
            colModel:[
                {
                    name:'resolution.resolution_id',index:'resolution.resolution_id',sorttype:'string', width:200
                },

            ],
            rowNum: 10000,
            pager:'#pager',
            toppager: true,
            viewrecords: true,
            sortname: 'resolution_id',
            jsonReader:{repeatitems: false,root:'resolution'},
            multiselect: true,
            gridview: true,
            caption: "Resolution"
          })

如何设置 JSON 映射以便它可以读取 resolution.resolution_id?

我尝试过各种 jsonmap:resolution.resolution_id.val 的组合

也试过

jsonmap:function(row){return row["val"]}

无济于事

【问题讨论】:

    标签: json jqgrid


    【解决方案1】:

    试试这个 colModel 和下面的 jsonmap:

    colModel:[
    {
        name:'resolution.resolution_id',
        index:'resolution.resolution_id',
        jsonmap : function (a) { var v = a["resolution.resolution_id"]; return v.val; },
        sorttype:'string', 
        width:200
    },
    ....
    ]
    

    或简单

    jsonmap : function (a) { return a["resolution.resolution_id"].val; },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-02
      • 1970-01-01
      • 2018-05-09
      相关资源
      最近更新 更多