/** * 返回树JSON数据 * * @param extCode * @param isShowHide * @param response * @return */ @RequiresPermissions("user") @ResponseBody @RequestMapping(value = "treeData") public List<Map<String, Object>> treeData(HttpServletResponse response) { List<Map<String, Object>> mapList = Lists.newArrayList(); List<ProjectType> list = projectTypeService.findList(new ProjectType()); //获取第一级节点 List<ProjectType> fristLevelList=new ArrayList<ProjectType>(); for (int i = 0; i < list.size(); i++) { ProjectType e = list.get(i); Map<String, Object> map = Maps.newHashMap(); if(" ".equals(e.getParentCode().getTypeCode())){ map.put("id", e.getTypeCode()); map.put("pId", e.getParentCode().getTypeCode()); map.put("name", e.getTypeName()); mapList.add(map); fristLevelList.add(e); } } //二级节点 List<ProjectType> secondLevelList=new ArrayList<ProjectType>(); for (ProjectType fristProjectType : fristLevelList) { for (ProjectType secondProjectType : list) { Map<String, Object> map = Maps.newHashMap(); if(fristProjectType.getTypeCode().equals(secondProjectType.getParentCode().getTypeCode())){ map.put("id", secondProjectType.getTypeCode()); map.put("pId", secondProjectType.getParentCode().getTypeCode()); map.put("name", secondProjectType.getTypeName()); mapList.add(map); secondLevelList.add(secondProjectType); } } } //三级节点 for (ProjectType secondProjectType : secondLevelList) { for (ProjectType thridProjectType : list) { Map<String, Object> map = Maps.newHashMap(); if(secondProjectType.getTypeCode().equals(thridProjectType.getParentCode().getTypeCode())){ map.put("id", thridProjectType.getTypeCode()); map.put("pId", thridProjectType.getParentCode().getTypeCode()); map.put("name", thridProjectType.getTypeName()); mapList.add(map); } } } return mapList; }
jsp:
<div class="input-inline width-160">
<sys:treeselect id="projectType_typeName"
name="projectType.typeCode" value="${projectType.typeCode }"
labelName="projectType.typeName"
labelValue="${projectType.typeName }" title="计划类别:"
url="/prg/projectType/treeData" cssClass="required"
allowClear="true" notAllowSelectParent="true" checked="true" />
</div>
时间: 2024-10-27 06:59:46