private void BuildMenuList_inter(MenuListNode parent, List <MenuListNode> list) { List <Menu> childs = GetChildsMenu(parent.Menu_Id); foreach (Menu m in childs) { MenuListNode mn = new MenuListNode(); mn.Menu_Id = m.Menu_Id; mn.Menu_Name = m.Menu_Name; mn.Menu_Icon = m.Menu_Icon; mn.Link_Url = m.Link_Url; if (m.Link_Url != null) { //在前台的页面中,本意是选择用Link_Url作为一个标签的id值,但是在id值中出现“/”的情况会使得根据id选择对象时出现问题,故在此统一转换。这段添加的代码功能是:将例如“/A3dot/Index”的字符串转成“A3dot3” string[] s = (m.Link_Url).Split(new char[] { '/' }); string str = s[1]; mn.url_id = str; } ; mn.Parent_id = parent.Menu_Id; mn.level = parent.level + 1; parent.Childs.Add(mn.Menu_Id); list.Add(mn); BuildMenuList_inter(mn, list); mn.Childs.ForEach(i => parent.Childs.Add(i)); } }
public List <MenuListNode> BuildMenuList() { Menu root = GetRootItem(); MenuListNode rmn = new MenuListNode(); rmn.Menu_Id = root.Menu_Id; rmn.Menu_Name = root.Menu_Name; rmn.Menu_Icon = root.Menu_Icon; rmn.Link_Url = root.Link_Url; rmn.level = -1; List <MenuListNode> list = new List <MenuListNode>(); BuildMenuList_inter(rmn, list); foreach (MenuListNode mn in list) { if (mn.Parent_id == root.Menu_Id) { mn.Parent_id = 0; } } return(list); }