private treedata getNode(SysOrg item, List <SysOrg> col3) { treedata node = new treedata() { id = item.id, name = item.org_name, enabled = item.dept_type, pid = item.parent_id, createTime = item.created_time.ToString(), label = item.org_name }; List <SysOrg> childs = col3.Where(t => t.parent_id == item.id).ToList(); if (childs.Count() > 0) { List <treedata> children = new List <treedata>(); foreach (var childitem in childs) { treedata childnode = getNode(childitem, col3); children.Add(childnode); } node.children = children; } return(node); }
public ResponseMessage <object> QueryDataByNameAndType([FromBody] QueryByPageRequest reqMsg) { List <treedata> reslst = new List <treedata>(); List <SysOrg> col1 = _sysOrgService.GetAll(); List <SysOrg> col2 = _sysOrgService.QueryDataByNameAndType(reqMsg.keyWords, reqMsg.status); SysOrg[] arr = new SysOrg[col2.Count()]; List <SysOrg> col3 = new List <SysOrg>(); col2.CopyTo(arr); col3 = arr.ToList(); foreach (var item in col2) { //补全树 getTree(col1, col3, item); } //构建树结果 foreach (SysOrg item in col3.Where(t => t.parent_id == "0")) { treedata node = getNode(item, col3); reslst.Add(node); } return(new ResponseMessage <object> { data = new { content = reslst, totalElements = col3.Count } }); }