/// <summary> /// 生成指定模块下的菜单 /// </summary> /// <param name="moudle"></param> /// <returns></returns> public string GenerateMenu(Module moudle) { if (moudle == null) throw new ArgumentNullException("moudle"); StringBuilder sb = new StringBuilder(); sb.AppendFormat(_JSITEMFORMAT, moudle.MoudleCaption); IEnumerable<Menu> menus = moudle.Menus; if (menus != null) { foreach (Menu m in menus) { if (_VISIBLEVALIDATE && !m.Visible) continue; GetMenuString(m, sb, 0, 1); } } return sb.ToString(); }
/// <summary> /// 生成菜单的HTML代码 /// </summary> /// <param name="moudle"></param> /// <returns></returns> public string GenerateMenu(Module moudle) { if (moudle == null) throw new ArgumentNullException("moudle"); var sb = new StringBuilder(); IEnumerable<Menu> menus = moudle.Menus; sb.AppendLine(string.Format(MenuCurrentMoudleFormatString, moudle.MoudleCaption, moudle.Href)); var tagBuildertmp = new TagBuilder(WarpParentTag); if (!string.IsNullOrEmpty(WarpParentCssClass)) tagBuildertmp.AddCssClass(WarpParentCssClass); if (menus != null) foreach (Menu m in menus) { if (!m.Visible) continue; if (m.IsOpen && m.ChildNodes.Count > 0) tagBuildertmp.InnerHtml += string.Format(RootMenuOpenFormatString, m.Href, m.CssClass,m.MenuTitle, m.MenuTitle, m.IsCurrent ? " on" : "") + Identy; else tagBuildertmp.InnerHtml += string.Format(RootMenuCloseFormatString, m.Href, m.CssClass, m.MenuTitle, m.MenuTitle, m.IsCurrent ? " on" : "") + Identy; if (m.ChildNodes != null && m.ChildNodes.Count>0) { var tagBuilder = new TagBuilder(WarpChildTag); if (!string.IsNullOrEmpty(WarpChildTagCssClass)) tagBuilder.AddCssClass(WarpChildTagCssClass); foreach (Menu n in m.ChildNodes) { if (!n.Visible) continue; if (n == Menu.Current) tagBuilder.InnerHtml += string.Format(CurrentMenuFormatString, n.Href, CurrentMenuCss, n.MenuTitle) + Identy; else tagBuilder.InnerHtml += string.Format(ChildMenuFormatString, n.Href, n.MenuTitle) + Identy; } tagBuildertmp.InnerHtml += new TagBuilder("li") { InnerHtml = tagBuilder.ToString() } + Identy; } } sb.AppendLine(tagBuildertmp.ToString()); return sb.ToString(); }