首页 > 代码库 > EasyUI TreeJson
EasyUI TreeJson
1. TreeJson
str = GetTreeJsonByTable(dt, "id", "fid", "0");
StringBuilder treeResult = new StringBuilder(); StringBuilder treesb = new StringBuilder(); public string GetTreeJsonByTable(DataTable tabel, string idCol, string rela, object pId) { string treeJson = string.Empty; treeResult.Append(treesb.ToString()); treesb.Clear(); if (tabel.Rows.Count > 0) { treesb.Append("["); string filer = string.Empty; if (pId.ToString() == "") { filer = string.Format("{0} is null", rela); } else { filer = string.Format("{0}=‘{1}‘", rela, pId); } DataRow[] rowtote = tabel.Select(filer); if (rowtote.Length > 0) { //foreach (DataRow row in rows) for (int i = 0; i < (rowtote.Length); i++) { treesb.Append("{"); for (int j = 0; j < tabel.Columns.Count; j++) { treesb.Append("\""); treesb.Append(tabel.Columns[j].ColumnName); treesb.Append("\":\""); treesb.Append(rowtote[i][j].ToString()); treesb.Append("\","); } treesb.Remove(treesb.Length - 1, 1); if (tabel.Select(string.Format("{0}=‘{1}‘", rela, rowtote[i][idCol])).Length > 0) { treesb.Append(",\"children\":"); GetTreeJsonByTable(tabel, idCol, rela, rowtote[i][idCol]); treeResult.Append(treesb.ToString()); treesb.Clear(); } treeResult.Append(treesb.ToString()); treesb.Clear(); treesb.Append("},"); } treesb = treesb.Remove(treesb.Length - 1, 1); } treesb.Append("]"); treeResult.Append(treesb.ToString()); treeJson = treeResult.ToString(); treesb.Clear(); } return treeJson; }
EasyUI TreeJson
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。