Пример #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);
        }
Пример #2
0
        /// <summary>设置默认数据</summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static TreeMenuNode ResetTreeNode(TreeMenuNode node)
        {
            if (node == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(node.DirImage))
            {
                node.DirImage = TreeMenuRoot.ImagePath;
            }
            if (String.IsNullOrEmpty(node.DirImageOpen))
            {
                node.DirImageOpen = TreeMenuRoot.ImageOpenPath;
            }
            if (String.IsNullOrEmpty(node.PagerImage))
            {
                node.PagerImage = TreeMenuRoot.ImagePagePath;
            }

            //if (node.Childs != null && node.Childs.Count > 0)
            //{
            //    if (String.IsNullOrEmpty(node.Image))
            //        node.Image = TreeMenuRoot.ImagePath;
            //    if (String.IsNullOrEmpty(node.ImageOpen))
            //        node.ImageOpen = TreeMenuRoot.ImageOpenPath;
            //}
            //else
            //{
            //    if (String.IsNullOrEmpty(node.Image))
            //        node.Image = TreeMenuRoot.ImagePagePath;
            //    if (String.IsNullOrEmpty(node.ImageOpen))
            //        node.ImageOpen = TreeMenuRoot.ImagePagePath;
            //}

            return(node);
        }
Пример #3
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);
        }