Esempio n. 1
0
        /// <summary>通过节点列表</summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="nodeList"></param>
        /// <param name="getChildsfun"></param>
        /// <param name="convertToTreeMenu"></param>
        /// <returns></returns>
        public static TreeMenuRoot GetTreeMenuRoot <T>(List <T> nodeList, Func <T, List <T> > getChildsfun, Func <T, TreeMenuNode> convertToTreeMenu)
        {
            TreeMenuRoot root = new TreeMenuRoot();

            root.Nodes = new List <TreeMenuNode>();
            if (nodeList != null && nodeList.Count > 0)
            {
                foreach (T item in nodeList)
                {
                    TreeMenuNode menu = convertToTreeMenu(item);
                    if (menu != null)
                    {
                        root.Nodes.Add(menu);
                        menu.Childs = GetTreeMenu <T>(item, getChildsfun, convertToTreeMenu);

                        menu.ResetImage();
                    }
                }
            }

            return(root);
        }
Esempio n. 2
0
        /// <summary>获取菜单树</summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rootNode"></param>
        /// <param name="getChildsfun"></param>
        /// <param name="convertToTreeMenu"></param>
        /// <returns></returns>
        private static List <TreeMenuNode> GetTreeMenu <T>(T rootNode, Func <T, List <T> > getChildsfun, Func <T, TreeMenuNode> convertToTreeMenu)
        {
            //Root root = new Root();
            List <TreeMenuNode> r = new List <TreeMenuNode>();

            List <T> list = getChildsfun(rootNode);

            if (list != null && list.Count > 0)
            {
                foreach (T item in list)
                {
                    TreeMenuNode menu = convertToTreeMenu(item);
                    if (menu != null)
                    {
                        r.Add(menu);
                        menu.Childs = GetTreeMenu <T>(item, getChildsfun, convertToTreeMenu);

                        menu.ResetImage();
                    }
                }
            }

            return(r.Count > 0 ? r : null);
        }