using System.Collections.Generic; using System.Text; namespace Znyc.Cloudcar.Admin.Commons.Tree { /// /// public static class TreeView { /// /// /// /// /// public static string TreeViewJson(this List data, int ParentId = 0) { StringBuilder strJson = new StringBuilder(); //List item = data.FindAll(t => t.ParentId == ParentId); //strJson.Append("["); //if (item.Count > 0) //{ // foreach (TreeViewModel entity in item) // { // strJson.Append("{"); // strJson.Append("\"id\":\"" + entity.id + "\","); // strJson.Append("\"text\":\"" + entity.text.Replace(" ", "") + "\","); // strJson.Append("\"value\":\"" + entity.value + "\","); // if (entity.title != null && !string.IsNullOrEmpty(entity.title.Replace(" ", ""))) // { // strJson.Append("\"title\":\"" + entity.title.Replace(" ", "") + "\","); // } // if (entity.img != null && !string.IsNullOrEmpty(entity.img.Replace(" ", ""))) // { // strJson.Append("\"img\":\"" + entity.img.Replace(" ", "") + "\","); // } // if (entity.checkstate != null) // { // strJson.Append("\"checkstate\":" + entity.checkstate + ","); // } // if (entity.ParentId != null) // { // strJson.Append("\"parentnodes\":\"" + entity.ParentId + "\","); // } // strJson.Append("\"showcheck\":" + entity.showcheck.ToString().ToLower() + ","); // strJson.Append("\"isexpand\":" + entity.isexpand.ToString().ToLower() + ","); // if (entity.complete == true) // { // strJson.Append("\"complete\":" + entity.complete.ToString().ToLower() + ","); // } // strJson.Append("\"hasChildren\":" + entity.hasChildren.ToString().ToLower() + ","); // strJson.Append("\"ChildNodes\":" + TreeViewJson(data, entity.id) + ""); // strJson.Append("},"); // } // strJson = strJson.Remove(strJson.Length - 1, 1); //} //strJson.Append("]"); return strJson.ToString(); } } }