2014-05-14 49 views
0

我對jqgrid相當陌生 如何顯示jqgrid中的嵌套json對象作爲單獨的字段? 下面給出的是JSON對象的研究相當如何在Jqgrid中顯示嵌套的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 東西將是非常有益 由於事先的例子

回答

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,你可能會找到你想要的。祝你好運!

+0

我試過用但不適用於我 我很困惑我應該加入什麼樣的根 你能不能更詳細地討論這個問題? 因爲我無法找到與此特定格式 jsonReader json的一個解決方案:{ repeatitems:真實, 根:「孩子們」 } –

+0

我已經編輯我的答案 – lucasdc

+0

感謝lucasdc 令人驚訝的是這樣的我現在正在使用類似的方法(在發佈問題之前) 但是這種方法只會給出一組值 json我recevie將有多個值 這意味着值的0在「children.0.properties .client「往往會改變 ,我必須做多個字段的合併 目前我是你sing formatter function formatter:function myFormatter(cellvalue,options,rowObject){ return rowObject.children.0.properties.client + rowObject.children.0.properties。鍵入 } –