/// <summary> /// 获取资源分类 /// </summary> /// <param name="db"></param> /// <returns></returns> public List <ComboTreeModels> GetResTypeList(string type, JSZX_ResourceEntities db) { List <T_Res_Type> list = new List <T_Res_Type>(); var query = from t in db.T_Res_Type orderby t.BELONG_ID, t.ID select t; query = query.OrderBy(t => t.CREATETIME); list = query.ToList(); List <ComboTreeModels> treeList = new List <ComboTreeModels>(); if (list != null && list.Count > 0) { ReturnTreeList(list, null, 1, ref treeList); if (type == "combox") { ComboTreeModels tree1 = new ComboTreeModels(); tree1.id = ""; tree1.text = ""; tree1.belong = ""; treeList.Insert(0, tree1); } } return(treeList); }
private void ReturnTreeList(List <T_Res_Type> list, string parentID, int num, ref List <ComboTreeModels> treeList) { List <T_Res_Type> t = FindById(list, parentID); if (t.Count > 0) { foreach (T_Res_Type resType in t) { ComboTreeModels tree = new ComboTreeModels(); tree.id = resType.ID; tree.text = resType.NAME; tree.belong = num.ToString(); List <ComboTreeModels> newTreeList = new List <ComboTreeModels>(); tree.children = newTreeList; treeList.Add(tree); ReturnTreeList(list, resType.ID, num + 1, ref newTreeList); } } else { return; } }