添加项目文件。
This commit is contained in:
60
HT.Cloud.Code/Web/TreeGrid/TreeGrid.cs
Normal file
60
HT.Cloud.Code/Web/TreeGrid/TreeGrid.cs
Normal file
@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright © 2016 HT.Cloud.Framework 版权所有
|
||||
* Author: HT.Cloud
|
||||
* Description: WaterCloud快速开发平台
|
||||
* Website:
|
||||
*********************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace HT.Cloud.Code
|
||||
{
|
||||
public static class TreeGrid
|
||||
{
|
||||
public static string TreeGridJson(this List<TreeGridModel> data)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(TreeGridJson(data, "0"));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static string TreeGridJson(List<TreeGridModel> data, string parentId)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var ChildNodeList = data.FindAll(t => t.parentId == parentId);
|
||||
sb.Append("[");
|
||||
if (ChildNodeList.Count > 0)
|
||||
{
|
||||
foreach (TreeGridModel entity in ChildNodeList)
|
||||
{
|
||||
string strJson = entity.ToJson() + ",";
|
||||
strJson = strJson.Insert(1, "\"children\":" + TreeGridJson(data, entity.id) + ",");
|
||||
sb.Append(strJson);
|
||||
}
|
||||
sb = sb.Remove(sb.Length - 1, 1);
|
||||
}
|
||||
|
||||
sb.Append("]");
|
||||
return sb.ToString().Replace("}{", "},{");
|
||||
}
|
||||
|
||||
public static List<TreeGridModel> TreeList(this List<TreeGridModel> data)
|
||||
{
|
||||
return TreeList(data, "0");
|
||||
}
|
||||
|
||||
private static List<TreeGridModel> TreeList(List<TreeGridModel> data, string parentId)
|
||||
{
|
||||
var ChildNodeList = data.FindAll(t => t.parentId == parentId);
|
||||
if (ChildNodeList.Count > 0)
|
||||
{
|
||||
foreach (TreeGridModel entity in ChildNodeList)
|
||||
{
|
||||
entity.children = TreeList(data, entity.id);
|
||||
}
|
||||
}
|
||||
return ChildNodeList;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user