public static List<IAntTreeNodeDto> ConvertToTree(this List<IAntTreeNodeDto> items,long? parentId=null)
{
var treeItems = items.Where(i => i.ParentId == parentId);
foreach(var treeItem in treeItems)
{
treeItem.Children = ConvertToTree(items, treeItem.Id);
}
return treeItems.ToList();
}
public interface IAntTreeNodeDto
{
public long Id { get; set; }
public long? ParentId { get; set; }
public string Title { get; set; }
public string Value { get; set; }
public int Weight { get; set; }
public List<IAntTreeNodeDto> Children { get; set; }
}
public class AntTreeNodeDto : IAntTreeNodeDto
{
public long Id { get; set; }
public long? ParentId { get; set; }
public string Title { get; set; }
public string Value { get; set; }
public int Weight { get; set; }
public List<IAntTreeNodeDto> Children { get; set; }
}