private List <SelectTree> GetChildrens <T>(List <T> menuList, Guid id) where T : BaseMenu
        {
            var treeList = new List <SelectTree>();
            var menus    = menuList.Where(d => d.ParentId == id);

            foreach (var menu in menus)
            {
                var tree     = new SelectTree();
                var menutype = menu.GetType().GetProperties();
                foreach (var items in tree.GetType().GetProperties())
                {
                    foreach (var item in menutype)
                    {
                        if (item.Name == items.Name)
                        {
                            items.SetValue(tree, item.GetValue(menu));
                            break;
                        }
                    }
                }
                tree.Children = GetChildrens(menuList, menu.Id);



                treeList.Add(tree);
            }
            return(treeList);
        }
        public async Task <IActionResult> GetTreeList()
        {
            var getResult = await _menuServices.GetListAsync(Specification <Menu> .Eval(d => !d.IsDelete));

            var menuList = getResult.data;
            var topMenu  = menuList.Where(d => d.ParentId == null).ToList();
            var treeList = new List <SelectTree>();

            //foreach (var menu in topMenu)
            //{
            //    var tree = new Tree();
            //    tree.Id = menu.Id;
            //    tree.Name = menu.Name;
            //    tree.Open = true;
            //    tree.Children = GetChildren(menuList,menu.Id);
            //    treeList.Add(tree);
            //}
            foreach (var menu in topMenu)
            {
                var tree = new SelectTree();
                tree.Id       = menu.Id;
                tree.Name     = menu.Name;
                tree.Open     = true;
                tree.Children = GetChildrens(menuList, menu.Id);
                treeList.Add(tree);
            }
            return(Json(treeList));
        }
Exemple #3
0
        public ActionResult GetTreeSelectJson(string moduleId)
        {
            var data     = App.GetButtonList(moduleId);
            var treeList = new List <SelectTree>();

            foreach (var item in data)
            {
                var treeModel = new SelectTree();
                treeModel.Id       = item.Id;
                treeModel.Text     = item.Name;
                treeModel.ParentId = item.ParentId;
                treeList.Add(treeModel);
            }
            return(Content(treeList.TreeSelectJson()));
        }
        /// <summary>
        /// 递归
        /// </summary>
        /// <param name="menuList"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private List <SelectTree> GetChildren(List <Menu> menuList, Guid id)
        {
            var treeList = new List <SelectTree>();
            var menus    = menuList.Where(d => d.ParentId == id);

            foreach (var menu in menus)
            {
                var tree = new SelectTree();
                tree.Id       = menu.Id;
                tree.Name     = menu.Name;
                tree.Children = GetChildren(menuList, menu.Id);
                treeList.Add(tree);
            }
            return(treeList);
        }
        public ActionResult GetTreeSelectJson()
        {
            var data     = App.GetAll();
            var treeList = new List <SelectTree>();

            foreach (var item in data)
            {
                var treeModel = new SelectTree
                {
                    Id       = item.Id,
                    Text     = item.Name,
                    ParentId = item.ParentId
                };
                treeList.Add(treeModel);
            }
            return(Content(treeList.TreeSelectJson()));
        }