纽威
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.
 
 
 
 
 

39 lines
1.2 KiB

using System.Collections.Generic;
using System.Text;
namespace NFine.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("}{", "},{");
}
}
}