public object Create(object parent, object configContext, System.Xml.XmlNode section) { List<CascadeMenu> items = null; CascadeMenu menu = null; try { if (section == null) throw new Exception("Menu section in web config is not defined"); items = new List<CascadeMenu>(); foreach (XmlNode menuNode in section.ChildNodes) { menu = new CascadeMenu { Id = int.Parse(menuNode.Attributes["Id"].Value), Action = menuNode.Attributes["Action"].Value, Controller = menuNode.Attributes["Controller"].Value, IsActive = Convert.ToBoolean(menuNode.Attributes["IsActive"].Value), ParentId = int.Parse(menuNode.Attributes["ParentId"].Value), SortOrder = int.Parse(menuNode.Attributes["SortOrder"].Value), Text = menuNode.Attributes["Text"].Value, IsVisible = Convert.ToBoolean(menuNode.Attributes["IsVisible"].Value), Roles = menuNode.Attributes["Roles"].Value.Split(new char[] { ',' }) }; if (menuNode.Attributes["Area"] != null) menu.Area = menuNode.Attributes["Area"].Value; items.Add(menu); } return items; } catch (Exception ex) { throw ex; } }
/// <summary> /// 添加子项 /// </summary> private void InitItems() { if (Items == null || Items.Count <= 0 || _subMenu != null) return; // 没有数据源 或 已初始化 _subMenu = new CascadeMenu(false) { Items = Items, }; _subMenu.SelectionChanged += _subMenu_SelectionChanged; }