/// <summary> /// 生成菜单树 /// </summary> /// <param name="menus"></param> /// <param name="parentMenuId"></param> /// <param name="nodes"></param> private int ResolveMenuTree(List<Menu> menus, Menu parentMenu, FineUI.TreeNodeCollection nodes) { int count = 0; foreach (var menu in menus.Where(m => m.Parent == parentMenu)) { FineUI.TreeNode node = new FineUI.TreeNode(); nodes.Add(node); count++; node.Text = menu.Name; node.IconUrl = menu.ImageUrl; if (!String.IsNullOrEmpty(menu.NavigateUrl)) { node.EnablePostBack = false; node.NavigateUrl = ResolveUrl(menu.NavigateUrl); //node.OnClientClick = String.Format("addTab('{0}','{1}','{2}')", node.NodeID, ResolveUrl(menu.NavigateUrl), node.Text.Replace("'", "")); } if (menu.IsTreeLeaf) { node.Leaf = true; // 如果是叶子节点,但是不是超链接,则是空目录,删除 if (String.IsNullOrEmpty(menu.NavigateUrl)) { nodes.Remove(node); count--; } } else { node.SingleClickExpand = true; int childCount = ResolveMenuTree(menus, menu, node.Nodes); // 如果是目录,但是计算的子节点数为0,可能目录里面的都是空目录,则要删除此父目录 if (childCount == 0 && String.IsNullOrEmpty(menu.NavigateUrl)) { nodes.Remove(node); count--; } } } return count; }
protected void CreateNode(string parentID, FineUI.TreeNodeCollection pnode, string RightStr) { foreach (sys_Menu m in sysMenuList.Where(p => p.PId == parentID).OrderBy(p => p.SortIndex).ToList()) { if (!RightStr.Contains(m.MenuCode + "-0")) continue; FineUI.TreeNode node = new FineUI.TreeNode(); pnode.Add(node); node.NodeID = m.MenuCode; node.Text = m.MenuName; node.NavigateUrl = ResolveUrl(m.Url); node.IconUrl = m.Ico; CreateNode(m.Id, node.Nodes, RightStr); } }