//部门树$("#dept").combotree({ editable: false, url: '@Url.Content("~/DetReport/DetReportManage/GetDeptTree")', onSelect: function (node) { //加载检测项目 $("#testItem").combotree({ editable: false, url: '@Url.Content("~/DetReport/YSLReport/GetTestItemTree?deptCode=")' + node.id, onSelect: function (node) { //显示全路径 var parent = node; var tree = $('#testItem').combotree('tree'); var path = new Array(); do { path.unshift(parent.text); var parent = tree.tree('getParent', parent.target); } while (parent); var pathStr = ''; for (var i = 0; i < path.length; i++) { pathStr += path[i]; if (i < path.length - 1) { pathStr += ' - '; } } setTimeout(function () { $('input[name="testItem"]').prev().val(pathStr); }, 100); } }); }});
View Code
后台代码1:
/// /// 获取部门树/// public JsonResult GetDeptTree(){ List
View Code
后台代码2:
/// /// 获取检测项目树(统计用)/// public JsonResult GetTestItemTree(string deptCode){ List list = new List(); List deptListAll = m_DeptDal.GetDeptListAll(); List itemListAll = m_DetectionItemsDAL.GetDetectionItemsListAll(); List specialtyListAll = m_SpecialtyDAL.GetSpecialtyListAll(); List deptList = deptListAll.FindAll(a => a.DEPTCODE.IndexOf(deptCode) == 0); if (deptList.Count > 0) { foreach (SPECIALTY specialty in specialtyListAll.FindAll(a => deptList.Exists(b => b.DEPTCODE == a.DEPTCODE))) { var specialtyObj = new { id = specialty.SPECIALTYID, text = specialty.SPECIALTYNAME, leaf = false, type = 1, //1专业2样品名称3检测项目 children = new List () }; foreach (DETECTIONITEMS items in itemListAll.FindAll(a => a.SPECIALTYID == specialty.SPECIALTYID && a.PID == 0)) { List subItemsList = itemListAll.FindAll(a => a.PID == items.DETITEMID); var itemsObj = new { id = items.DETITEMID, text = items.ITEMNAME, leaf = subItemsList.Count > 0 ? false : true, //只能选择leaf为true的节点 type = 2, //1专业2样品名称3检测项目 children = new List () }; foreach (DETECTIONITEMS subItems in subItemsList) { var subItemsObj = new { id = subItems.DETITEMID, text = subItems.ITEMNAME, leaf = true, //只能选择leaf为true的节点 type = 3, //1专业2样品名称3检测项目 children = new List() }; itemsObj.children.Add(subItemsObj); } specialtyObj.children.Add(itemsObj); } list.Add(specialtyObj); } } return Json(list, JsonRequestBehavior.AllowGet);}