2016-02-11 66 views
0

我想創建數據綁定到Telerik的treeview控件。該文件建議按照以下格式創建數據:如何在C#中創建分層數據

dataSource: 
[{ 
    id: 1, text: "My Documents", expanded: true, spriteCssClass: "rootfolder", items: [ 
     { 
      id: 2, text: "Kendo UI Project", expanded: true, spriteCssClass: "folder", items: [ 
       { id: 3, text: "about.html", spriteCssClass: "html" }, 
       { id: 4, text: "index.html", spriteCssClass: "html" }, 
       { id: 5, text: "logo.png", spriteCssClass: "image" } 
      ] 
     }, 
     { 
      id: 6, text: "New Web Site", expanded: true, spriteCssClass: "folder", items: [ 
       { id: 7, text: "mockup.jpg", spriteCssClass: "image" }, 
       { id: 8, text: "Research.pdf", spriteCssClass: "pdf" }, 
      ] 
     }, 
     { 
      id: 9, text: "Reports", expanded: true, spriteCssClass: "folder", items: [ 
       { id: 10, text: "February.pdf", spriteCssClass: "pdf" }, 
       { id: 11, text: "March.pdf", spriteCssClass: "pdf" }, 
       { id: 12, text: "April.pdf", spriteCssClass: "pdf" } 
      ] 
     } 
    ] 
}] 

我在SortedList<string, SortedList<string, IData>>格式的數據。我想在C#中將其轉換爲上述格式。

感謝

+0

看起來好像他們告訴你將其轉換爲JSON格式。如果你現在有一個排序列表,你怎麼知道什麼對象是另一個對象的子對象或父對象? – oppassum

回答

0

我不使用Telerik的,但的DevExpress(個人喜好,這是更好),而且我要告訴一個TreeView該場節點Id和字段是的ParentId。我建議你爲你的IData添加一個ParentId字段。

NodeId是樹將構建其視圖的唯一ID,ParentId是告訴Tree如何填充圖層的ID。

最後但並非最不重要的一個TreeView將需要RootId作爲列表的入口點。