Exemple #1
0
        //构建一个CategoryList的json
        public JsonResult TreeJson()
        {
            Category root     = unitOfWork.categorysRepository.GetByID(1);
            bvnode   rootnode = new bvnode();

            rootnode.text = root.CategoryName;
            rootnode.id   = root.ID;
            rootnode.pid  = root.CategoryParentID;
            LoopToAppendChildren(rootnode);
            return(Json(rootnode.nodes, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        //递归出所有字典数据
        public void LoopToAppendChildren(bvnode rootnode)
        {
            var subItems = Getnodes(rootnode.id);

            if (subItems.Count > 0)
            {
                rootnode.nodes = new List <bvnode>();
                rootnode.nodes.AddRange(subItems);
                foreach (var subItem in subItems)
                {
                    LoopToAppendChildren(subItem);
                }
            }
        }
Exemple #3
0
        public List <bvnode> Getnodes(int ParentID)
        {
            var categorys = from s in db.Categorys
                            orderby s.CategorySort ascending
                            where s.CategoryParentID == ParentID
                            select s;
            List <bvnode> nodes = new List <bvnode>();

            foreach (var category in categorys)
            {
                bvnode node = new bvnode();
                node.id   = category.ID;
                node.pid  = category.CategoryParentID;
                node.text = category.CategoryName;
                nodes.Add(node);
            }

            return(nodes.ToList());
        }