Files
HTCloud/HT.Cloud.Code/Web/Tree/TreeSelect.cs
2023-03-03 16:07:50 +08:00

47 lines
1.3 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*******************************************************************************
* 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 TreeSelect
{
public static string TreeSelectJson(this List<TreeSelectModel> data)
{
StringBuilder sb = new StringBuilder();
sb.Append("[");
sb.Append(TreeSelectJson(data, "0", ""));
sb.Append("]");
return sb.ToString();
}
private static string TreeSelectJson(List<TreeSelectModel> data, string parentId, string blank)
{
StringBuilder sb = new StringBuilder();
var ChildNodeList = data.FindAll(t => t.parentId == parentId);
var tabline = "";
if (parentId != "0")
{
tabline = "  ";
}
if (ChildNodeList.Count > 0)
{
tabline = tabline + blank;
}
foreach (TreeSelectModel entity in ChildNodeList)
{
entity.text = tabline + entity.text;
string strJson = entity.ToJson();
sb.Append(strJson);
sb.Append(TreeSelectJson(data, entity.id, tabline));
}
return sb.ToString().Replace("}{", "},{");
}
}
}