Ejemplo n.º 1
0
        /// <summary>
        /// 获取单个末端菜单的完整树菜单列表
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public List <Model.MenuInfo> GetMenuSingelTree(Model.MenuInfo menu)
        {
            List <Model.MenuInfo> result = new List <Model.MenuInfo>();

            if (menu.PreID.Equals(0))
            {
                result.Add(menu);
            }
            else
            {
                result.Add(menu);
                result.AddRange(GetMenuSingelTree(Get <Model.MenuInfo>(string.Format(" MenuID = {0} ", menu.PreID))));
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取指定节点下的完整树
        /// </summary>
        /// <param name="menu">指定节点</param>
        /// <param name="menuList">菜单树列表</param>
        /// <returns></returns>
        public string GetSingelTreeHtml(Model.MenuInfo menu, List <Model.MenuInfo> menuList)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<ul class=\"easyui-tree\">");

            List <Model.MenuInfo> childList = menuList.Where(p => p.PreID.Equals(menu.MenuID)).ToList();

            if (childList.Count > 0)
            {
                if (!string.IsNullOrWhiteSpace(menu.Url))
                {
                    sb.AppendFormat(@"<li data-options=""iconCls:'{0}',state:'closed'""><span><a href=""javascript:;"" icon=""{0}"" rel=""{2}"">{1}</a></span>", menu.ICOCSS, menu.NodeName, menu.Url);//<a href=""javascript:;"" icon=""{0}"" rel=""{1}"">{2}</a>
                }
                else
                {
                    sb.AppendFormat(@"<li data-options=""iconCls:'{0}',state:'closed'""><span>{1}</span>", menu.ICOCSS, menu.NodeName);
                }

                foreach (Model.MenuInfo item in childList)
                {
                    sb.Append(GetSingelTreeHtml(item, menuList));
                }

                sb.Append("</li>");
            }
            else
            {
                sb.AppendFormat(@"<li data-options=""iconCls:'{0}'""><a href=""javascript:;"" icon=""{0}"" rel=""{1}"">{2}</a></li>",
                                menu.ICOCSS,
                                menu.Url,
                                menu.NodeName
                                );
            }

            sb.Append("</ul>");
            return(sb.ToString());
        }