.Net递归加载菜单树

获取数据-递归加载

 private List<MenuTree> menuTrees = new List<MenuTree>();
        public async Task<IEnumerable<MenuTree>> GetMenuTrees()
        {
            IEnumerable<MenuTree> tree = await base.GetAllAsync();
            menuTrees = tree.ToList();
            return GetTree("0", menuTrees);

        }

        private List<MenuTree> GetTree(string printId, List<MenuTree> node)
        {
            List<MenuTree> mainNodes = node.Where(x => x.ParentMenuId == printId).ToList();
            List<MenuTree> otherNodes = node.Where(x => x.ParentMenuId != printId).ToList();
            foreach (MenuTree dpt in mainNodes)
            {
                dpt.Children = GetTree(dpt.MenuId, otherNodes);
            }
            return mainNodes;
        }

二、数据库表结构

CREATE TABLE [dbo].[Sys_Menu](
    [MenuId] [nvarchar](40) NOT NULL,
    [MenuName] [nvarchar](64) NOT NULL,
    [ParentMenuId] [nvarchar](40) NULL,
    [Level] [int] NULL,
    [Url] [nvarchar](256) NULL,
    [SourceType] [int] NULL,
    [Icon] [nvarchar](128) NULL,
    [OrderIndex] [int] NULL,
    [Deleted] [int] NOT NULL,
    [CreatedTime] [datetime] NULL,
    [CreatedBy] [bigint] NULL,
    [UpdatedTime] [datetime] NULL,
    [UpdatedBy] [bigint] NULL,
PRIMARY KEY CLUSTERED 
(
    [MenuId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

 

 

 

.Net递归加载菜单树

 

 

.Net递归加载菜单树

 

.Net递归加载菜单树

上一篇:Python玩具总动员之爬虫篇(一):urllib


下一篇:[js] - 为子节点增加鼠标移入和移出的样式