Exemple #1
0
        /// <summary>通过根节点获取</summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rootNode"></param>
        /// <param name="getChildsfun"></param>
        /// <param name="convertToTreeMenu"></param>
        /// <returns></returns>
        public static TreeMenuRoot GetTreeMenuRoot <T>(T rootNode, Func <T, List <T> > getChildsfun, Func <T, TreeMenuNode> convertToTreeMenu)
        {
            TreeMenuRoot root = new TreeMenuRoot();

            root.Nodes = GetTreeMenu <T>(rootNode, getChildsfun, convertToTreeMenu);

            return(root);
        }
Exemple #2
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);
        }