2013-06-12 162 views
1

我正在將jqgrid的豐富嵌套域對象傳遞爲平面數據行。我這樣做是因爲我想避免在我的應用程序中爲每個100 ++數據網格創建一個平坦的Java數據傳輸對象。樣本行數據:JQGrid:colmodel名稱衝突

<record> 
    <brand> 
    <description>The Brand</description> 
    <brandId>305</brandId> 
    </brand> 
    <description>The description</description> 
    <recordId>110</recordId> 
</record> 

不幸的是這會創建2個元件之間的命名衝突:品牌描述列顯示正常,但根說明列同時顯示「描述」級聯(「TheBrandThe描述」)。這裏是我的列模型:

colModel : 
    {name:'brand>description', index:"brand>brandId", 
     xmlmap:"brand>description",width:200}, 
    {name:'description', index:'description', xmlmap:"description", 
     editable:true, edittype:'text', width:500} 
] 

我應該如何修改列模型,以便有2「描述」之間沒有衝突?我試圖使用xmlmap,但沒有改變。謝謝!

回答

0

你應該做的是以下

  1. 你應該開始xmlmap>符號指定的XML項目的根路徑。
  2. 您應該使用對應於屬性名稱的name屬性colModel的值。例如name: 'brand'name: "brand_description"而不是name:'brand>description'
  3. 您最好不要指定任何index屬性作爲列描述。在這種情況下,jqGrid將在內部複製name屬性的值到index

The demo顯示結果。它採用

colNames: ["brandId", "brand description", "description", "recordId"], 
colModel: [ 
    { name: "brand_brandId", xmlmap: ">brand>brandId", key: true, width: 100}, 
    { name: "brand_description", xmlmap: ">brand>description", width: 200}, 
    { name: "description", xmlmap: ">description", editable: true, width: 500}, 
    { name: "recordId", width: 100} 
] 

我添加額外key: true">brand>brandId"的定義,因爲我假定值對每個項目唯一的,它可以被用來作爲ROWID。您可以用另一種原因選擇行的id

+0

謝謝Oleg!這部分不適合我:root:「> records」,row:「> record」(在xmlReader中),所以我刪除了'>'字符,但colModel中的更改工作正常。還有一個問題:如果我決定使用JSON數據而不是XML,我需要在colModel中更改哪些內容? – Pablo

+0

@ user2309409:您沒有發佈**完整的XML **文件,因此我不知道您是否正確設置了root:「> records」,row:「> record」'。在我的demo中,'records'是XML文件的* root *元素和XML項的'record'根。我建議你使用JSON而不是XML。您可能需要'jsonmap:「brand.description」'而不是'xmlmap:「> brand> description」'。 – Oleg

+0

好吧,我會檢查出來。而你是對的我的XML文件在頂部有一個級別..再次感謝您的幫助。 – Pablo