Esempio n. 1
0
 /// <summary>
 /// 将某个分类添加到tree的节点中
 /// </summary>
 /// <param name="cs">符合条件的分类信息</param>
 /// <param name="tree">树信息</param>
 private void AddTypeToTree(IEnumerable <Models.Category> cs, Models.FormatModel.TreeModel tree)
 {
     foreach (Models.Category item in cs)
     {
         if (tree.Contains(item.CategoryId))
         {
             continue;
         }
         Models.FormatModel.TreeModel t = new Models.FormatModel.TreeModel()
         {
             id = item.CategoryId, text = item.CategoryName
         };
         AddTypeToTree(cs.Where(type => type.ParentId == item.CategoryId), t);
     }
 }
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/plain";
     try
     {
         //转换为tree模型
         Models.FormatModel.TreeModel tree = CommonNews.Helper.OperateContext.Current.LoadAllTypesTreeNode();
         //转换为json格式数据输出
         string jsonData = Common.ConverterHelper.ObjectToJson(tree);
         context.Response.Write(jsonData);
     }
     catch (Exception ex)
     {
         new Common.LogHelper(typeof(getTypesNodeHandler)).Error(ex);
         context.Response.Write("error");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 加载所有分类到树
        /// </summary>
        /// <returns>树模型</returns>
        public Models.FormatModel.TreeModel LoadAllTypesTreeNode()
        {
            List <Models.Category> types = LoadNewsTypes();

            Models.FormatModel.TreeModel treeNodes = null;
            foreach (Models.Category item in (types.Where(t => t.ParentId == 0)))
            {
                if (treeNodes.Contains(item.CategoryId))
                {
                    continue;
                }
                Models.FormatModel.TreeModel tree = new Models.FormatModel.TreeModel()
                {
                    id = item.CategoryId, text = item.CategoryName
                };
                AddTypeToTree(types.Where(t => t.ParentId == item.CategoryId), tree);
            }
            return(treeNodes);
        }