code/Athena0.0.1/common/Util/WebControl/TreeView/TreeView.cs
(完整代码) 2KBusing System.Collections.Generic;
using System.Text;
namespace Athena.common.Util.WebControl
{
public static class TreeView
{
public static string TreeViewJson(this List<TreeViewModel> data, string parentId = null)
{
StringBuilder strJson = new StringBuilder();
List<TreeViewModel> 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();
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
