本文整理汇总了C#中TreeNode.Append方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.Append方法的具体用法?C# TreeNode.Append怎么用?C# TreeNode.Append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode
的用法示例。
在下文中一共展示了TreeNode.Append方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCategoryMenu
public TreeNode<MenuItem> GetCategoryMenu()
{
var customerRolesIds = _services.WorkContext.CurrentCustomer.CustomerRoles.Where(cr => cr.Active).Select(cr => cr.Id).ToList();
string cacheKey = string.Format(ModelCacheEventConsumer.CATEGORY_NAVIGATION_MODEL_KEY,
_services.WorkContext.WorkingLanguage.Id,
string.Join(",", customerRolesIds),
_services.StoreContext.CurrentStore.Id);
var model = _services.Cache.Get(cacheKey, () =>
{
var curParent = new TreeNode<MenuItem>(new MenuItem
{
EntityId = 0,
Text = "Home",
RouteName = "HomePage"
});
Category prevCat = null;
var categories = _categoryService.GetAllCategories();
foreach (var category in categories)
{
var menuItem = new MenuItem
{
EntityId = category.Id,
Text = category.GetLocalized(x => x.Name),
RouteName = "Category"
};
menuItem.RouteValues.Add("SeName", category.GetSeName());
// determine parent
if (prevCat != null)
{
if (category.ParentCategoryId != curParent.Value.EntityId)
{
if (category.ParentCategoryId == prevCat.Id)
{
// level +1
curParent = curParent.LastChild;
}
else
{
// level -x
while (!curParent.IsRoot)
{
if (curParent.Value.EntityId == category.ParentCategoryId)
{
break;
}
curParent = curParent.Parent;
}
}
}
}
// add to parent
curParent.Append(menuItem);
prevCat = category;
}
var root = curParent.Root;
// menu publisher
_menuPublisher.Value.RegisterMenus(root, "catalog");
// event
_services.EventPublisher.Publish(new NavigationModelBuiltEvent(root));
return root;
});
return model;
}
示例2: ConvertSitemapNodeToMenuItemNode
private TreeNode<MenuItem> ConvertSitemapNodeToMenuItemNode(SiteMapNode node)
{
var item = new MenuItem();
var treeNode = new TreeNode<MenuItem>(item);
if (node.RouteName.HasValue())
{
item.RouteName = node.RouteName;
}
else if (node.ActionName.HasValue() && node.ControllerName.HasValue())
{
item.ActionName = node.ActionName;
item.ControllerName = node.ControllerName;
}
else if (node.Url.HasValue())
{
item.Url = node.Url;
}
item.RouteValues = node.RouteValues;
item.Visible = node.Visible;
item.Text = node.Title;
item.Attributes.Merge(node.Attributes);
if (node.Attributes.ContainsKey("permissionNames"))
item.PermissionNames = node.Attributes["permissionNames"] as string;
if (node.Attributes.ContainsKey("id"))
item.Id = node.Attributes["id"] as string;
if (node.Attributes.ContainsKey("resKey"))
item.ResKey = node.Attributes["resKey"] as string;
if (node.Attributes.ContainsKey("iconClass"))
item.Icon = node.Attributes["iconClass"] as string;
if (node.Attributes.ContainsKey("imageUrl"))
item.ImageUrl = node.Attributes["imageUrl"] as string;
if (node.Attributes.ContainsKey("isGroupHeader"))
item.IsGroupHeader = Boolean.Parse(node.Attributes["isGroupHeader"] as string);
// iterate children recursively
foreach (var childNode in node.ChildNodes)
{
var childTreeNode = ConvertSitemapNodeToMenuItemNode(childNode);
treeNode.Append(childTreeNode);
}
return treeNode;
}
示例3: PrepareCategoryNavigationModel
protected TreeNode<CategoryNavigationModel.CategoryModel> PrepareCategoryNavigationModel()
{
var curParent = new TreeNode<CategoryNavigationModel.CategoryModel>(new CategoryNavigationModel.CategoryModel()
{
Id = 0,
Name = "_ROOT_",
Level = -1 // important
});
Category prevCat = null;
int level = 0;
var categories = _categoryService.GetAllCategories();
foreach (var category in categories)
{
var model = new CategoryNavigationModel.CategoryModel()
{
Id = category.Id,
Name = category.GetLocalized(x => x.Name),
SeName = category.GetSeName()
};
// determine parent
if (prevCat != null)
{
if (category.ParentCategoryId != curParent.Value.Id)
{
if (category.ParentCategoryId == prevCat.Id)
{
// level +1
curParent = curParent.LastChild;
level++;
}
else
{
// level -x
while (!curParent.IsRoot)
{
if (curParent.Value.Id == category.ParentCategoryId)
{
break;
}
curParent = curParent.Parent;
level--;
}
}
}
}
// set level
model.Level = level;
// add to parent
curParent.Append(model);
prevCat = category;
}
var root = curParent.Root;
// event
_eventPublisher.Publish(new NavigationModelBuiltEvent(root));
return root;
}