public IActionResult GetListToTree(string parentId) { var resultCountModel = new RespResultCountViewModel(); try { var data = parentId != null?_areaService.GetAll().Where(it => it.ParentId != parentId) : _areaService.GetAll(); var resData = LayuixTree.CreateTree( data.Where(it => it.ParentId == "0" || it.ParentId == null).Select(x => new TreeObject { id = x.AreaId, name = x.AreaName, @checked = true, open = true }).ToList(), data.Where(it => it.ParentId != "0" || it.ParentId != null).Select(x => new TreeObject { id = x.AreaId, name = x.AreaName, pId = x.ParentId, @checked = true, open = true }).ToList() ); if (resData != null) { return(Ok(resData)); } else { resultCountModel.code = -1; resultCountModel.msg = "没有检索到数据"; return(Ok(resultCountModel)); } } catch (Exception ex) { resultCountModel.code = -1; resultCountModel.msg = "操作失败:" + ex.ToString(); return(Ok(resultCountModel)); } }
public IActionResult GetTreeSelectAreaList(string AreaId) { var resultCountModel = new RespResultCountViewModel(); try { if (string.IsNullOrEmpty(AreaId)) { resultCountModel.code = -1; resultCountModel.msg = "没有地区ID"; return(Ok(resultCountModel)); } var data = _areaService.GetAll().Where(it => it.AreaId.Contains(AreaId)).ToList(); var resData = LayuixTree.CreateTree( data.Where(it => it.AreaId == AreaId).Select(x => new TreeObject { id = x.AreaId, name = x.AreaName, @checked = true, open = true }).ToList(), data.Where(it => it.AreaId != AreaId && it.AreaId.Contains(AreaId)).Select(x => new TreeObject { id = x.AreaId, name = x.AreaName, pId = x.ParentId, @checked = true, open = true }).ToList() ); if (resData != null) { return(Ok(resData)); } else { resultCountModel.code = -1; resultCountModel.msg = "没有检索到数据"; return(Ok(resultCountModel)); } } catch (Exception ex) { resultCountModel.code = -1; resultCountModel.msg = "操作失败:" + ex.ToString(); return(Ok(resultCountModel)); } }