码迷,mamicode.com
首页 > 其他好文 > 详细

节点 二级节点 三级节点 for循环 树结构

时间:2015-12-07 18:24:58      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

/**
     * 返回树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>

节点 二级节点 三级节点 for循环 树结构

标签:

原文地址:http://www.cnblogs.com/chuanqimessi/p/5026649.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!