public static MvcHtmlString Tree(this HtmlHelper hh, TreeWrap<CodeNote.Entity.Category> tree)
 {
     TagBuilder div = new TagBuilder("div");
     div.MergeAttribute("class", "tree");
     div.InnerHtml = InitTree(hh, tree);
     return MvcHtmlString.Create(div.ToString());
 }
Exemple #2
0
 private TreeWrap<Category> InitTree(TreeWrap<Category> root)
 {
     IList<Category> list = this.GetByParentID(root.CurNode.CategoryID);
     foreach (Category item in list)
     {
         TreeWrap<Category> subItem = new TreeWrap<Category>(item);
         InitTree(subItem);
         root.AddSubNode(subItem);
     }
     return root;
 }
 public static string InitTree(HtmlHelper hh, TreeWrap<CodeNote.Entity.Category> tree)
 {
     if (tree.IsSub)
     {
         TagBuilder ul = new TagBuilder("ul");
         StringBuilder sb = new StringBuilder();
         foreach (TreeWrap<CodeNote.Entity.Category> item in tree.SubNode)
         {
             TagBuilder li = new TagBuilder("li");
             TagBuilder label = new TagBuilder("label");
             string hid = string.Format("<input type=\"checkbox\" name=\"chkCategory\" value=\"{0}\" onchange=\"ChkCategoryChange(this)\" />", item.CurNode.CategoryID);
             label.MergeAttribute("title", item.CurNode.Title);
             label.InnerHtml = hid + "&nbsp;" + item.CurNode.Name + "(" + item.CurNode.Title + ")";
             li.InnerHtml = label.ToString() + InitTree(hh, item);
             sb.Append(li.ToString());
         }
         ul.InnerHtml = sb.ToString();
         return ul.ToString();
     }
     return string.Empty;
 }
Exemple #4
0
 /// <summary>
 /// 获取分类的树状列表
 /// </summary>
 /// <returns></returns>
 public TreeWrap<Category> GetCategoryTree()
 {
     TreeWrap<Category> tree = new TreeWrap<Category>();
     tree.CurNode = new Category() { CategoryID = "0", Name = "分类信息" };
     return InitTree(tree);
 }