using System.Collections.Generic;
using System.Text;
using Znyc.Recruitment.Admin.Commons.Json;
namespace Znyc.Recruitment.Admin.Commons.Tree
{
///
///
public static class TreeSelect
{
///
///
///
///
public static string TreeSelectJson(this List data)
{
StringBuilder sb = new StringBuilder();
sb.Append("[");
sb.Append(TreeSelectJson(data, 0, ""));
sb.Append("]");
return sb.ToString();
}
///
///
///
///
///
///
private static string TreeSelectJson(List data, int ParentId, string blank)
{
StringBuilder sb = new StringBuilder();
List 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("}{", "},{");
}
}
}