Beispiel #1
0
        //构建一个DictionaryList的json
        public JsonResult TreeJson()
        {
            Dictionary root     = db.Dictionarys.Find(1);
            bvnode     rootnode = new bvnode();

            rootnode.text = root.DictionaryName;
            rootnode.id   = root.ID;
            rootnode.pid  = root.DictionaryParentID;
            LoopToAppendChildren(rootnode);
            return(Json(rootnode.nodes, JsonRequestBehavior.AllowGet));
        }
Beispiel #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);
                }
            }
        }
Beispiel #3
0
        //数据库中的数据封装成jsonlist格式的node
        public List <bvnode> Getnodes(int ParentID)
        {
            var dictionarys = from s in db.Dictionarys
                              orderby s.DictionarySort ascending
                              where s.DictionaryParentID == ParentID
                              select s;
            List <bvnode> nodes = new List <bvnode>();

            foreach (var dictionary in dictionarys)
            {
                bvnode node = new bvnode();
                node.id   = dictionary.ID;
                node.pid  = dictionary.DictionaryParentID;
                node.text = dictionary.DictionaryName;
                nodes.Add(node);
            }

            return(nodes.ToList());
        }
        public List <bvnode> Getnodes(int ParentID)
        {
            var departments = from s in db.Departments
                              orderby s.DepartmentSort ascending
                              where s.DepartmentParentID == ParentID
                              select s;
            List <bvnode> nodes = new List <bvnode>();

            foreach (var department in departments)
            {
                bvnode node = new bvnode();
                node.id   = department.ID;
                node.pid  = department.DepartmentParentID;
                node.text = department.DepartmentName;
                nodes.Add(node);
            }

            return(nodes.ToList());
        }