主要的方法

        /// <summary>
/// 转化成树结构
/// </summary>
/// <param name="menuList">菜单的平级list</param>
/// <returns></returns>
private List<AbpMenuModel> GetTreeParent(List<AbpMenuDto> menuList)
{
var dic = new Dictionary<long, AbpMenuModel>(menuList.Count);
foreach (var chapter in menuList)
{
dic.Add(chapter.Id, new AbpMenuModel { Id = chapter.Id, Title = chapter.Title, Path = chapter.Path, ParentId = chapter.ParentId, Icon = chapter.Icon });
}
foreach (var chapter in dic.Values)
{
if (dic.ContainsKey(chapter.ParentId.Value))
{
if (dic[chapter.ParentId.Value].Children == null)
{
dic[chapter.ParentId.Value].Children = new List<AbpMenuModel>(); }
dic[chapter.ParentId.Value].Children.Add(chapter);
}
}
return dic.Values.Where(t => t.ParentId == ).ToList();
}

转换前的类

    [AutoMapTo(typeof(AbpMenuDto))]
public class AbpMenuDto : EntityDto<long>
{
/// <summary>
/// 路径
/// </summary>
public string Path { get; set; }
/// <summary>
/// 菜单名
/// </summary>
public string Title { get; set; }
/// <summary>
/// 图标
/// </summary>
public string Icon { get; set; } /// <summary>
/// 父级ID
/// </summary>
public long? ParentId { get; set; }
/// <summary>
/// 类型 菜单(menu) 还是 元素(doc)(按钮等)
/// </summary>
public string Type { get; set; }
/// <summary>
/// doc时 的父级下唯一代码
/// </summary>
public string Code { get; set; } /// <summary>
/// doc时 的名称
/// </summary>
public string Name { get; set; }
}

转换后的类

 public class AbpMenuModel : EntityDto<long>
{
/// <summary>
/// 路径
/// </summary>
public string Path { get; set; }
/// <summary>
/// 菜单名
/// </summary>
public string Title { get; set; }
/// <summary>
/// 图标
/// </summary>
public string Icon { get; set; } /// <summary>
/// 父级ID
/// </summary>
public long? ParentId { get; set; }
/// <summary>
/// 类型 菜单(menu) 还是 元素(doc)(按钮等)
/// </summary>
public string Type { get; set; }
/// <summary>
/// doc时 的父级下唯一代码
/// </summary>
public string Code { get; set; } /// <summary>
/// doc时 的名称
/// </summary>
public string Name { get; set; } public List<AbpMenuModel> Children { get; set; }

最新文章

  1. [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变
  2. 10 Symbol
  3. MySQL存储过程中实现回滚
  4. 处理xml c#
  5. 最近开发的ECG项目
  6. Hive 按某列的部分排序 以及 删列操作
  7. Linux常用服务部署与优化之Samba篇
  8. HDU 1429 (BFS+记忆化状压搜索)
  9. C118 免按开机自动加载固件
  10. wikioi 1204 寻找子串位置
  11. Windows系统性能提升方法
  12. Java笔记(十九)&hellip;&hellip;多线程
  13. windows下使用waveout函数族播放wav文件
  14. 201521123108 《Java程序设计》第13周学习总结
  15. CodeForces839-B. Game of the Rows-水题(贪心)
  16. [LeetCode] Smallest Good Base 最小的好基数
  17. 网卡的 Ring Buffer 详解
  18. 数据定义语言(DDL Data Definition Language)基础学习笔记
  19. 学生月上网时间分布-TestData
  20. Alpha冲刺8

热门文章

  1. HTTP协议那些事儿
  2. Docker安装Redis4.0
  3. woocommerce隐藏breadcrumb面包屑导航
  4. Comet OJ - Contest #2题解
  5. 【Excel】去空格
  6. Scrapy笔记04- Selector详解
  7. xshell跳转设置 Xshell代理设置
  8. Linux操作中应该注意的问题
  9. I/O管理杂记
  10. 2090. 「ZJOI2016」旅行者 分治,最短路