You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
56 lines
1.7 KiB
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Znyc.Cloudcar.Admin.Commons.Json;
|
|
|
|
namespace Znyc.Cloudcar.Admin.Commons.Tree
|
|
{
|
|
/// <summary>
|
|
/// </summary>
|
|
public static class TreeSelect
|
|
{
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <returns></returns>
|
|
public static string TreeSelectJson(this List<TreeSelectModel> data)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("[");
|
|
sb.Append(TreeSelectJson(data, 0, ""));
|
|
sb.Append("]");
|
|
return sb.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
/// <param name="ParentId"></param>
|
|
/// <param name="blank"></param>
|
|
/// <returns></returns>
|
|
private static string TreeSelectJson(List<TreeSelectModel> data, int ParentId, string blank)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
List<TreeSelectModel> ChildNodeList = data.FindAll(t => t.ParentId == ParentId);
|
|
string tabline = "";
|
|
if (!string.IsNullOrEmpty(ParentId.ToString()))
|
|
{
|
|
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("}{", "},{");
|
|
}
|
|
}
|
|
}
|