프런트에서 드롭다운 트리 구현 - Treeselect

3267 단어 프런트엔드
이틀 동안 Treeselect를 계속 연구했어요.
백엔드에서 데이터를 받아treeselect에 넣기
Controller:
/**
     *        
     *
     * @param excludeCode    Code
     * @param isShowCode       (true or 1:     ;2:     ;false or null:   )
     * @return
     */
    @RequestMapping(value = "officeListData")
    @ResponseBody
    public List> officeListData(String excludeCode, String isShowCode) {
        List> mapList = ListUtils.newArrayList();
        List list = officeService.findList(new Office());
        for (int i = 0; i < list.size(); i++) {
            Office e = list.get(i);
            //         
            if (!Office.STATUS_NORMAL.equals(e.getStatus())) {
                continue;
            }
            //         (      )
            if (StringUtils.isNotBlank(excludeCode)) {
                if (e.getId().equals(excludeCode)) {
                    continue;
                }
                if (e.getParentCodes().contains("," + excludeCode + ",")) {
                    continue;
                }
            }
            Map map = MapUtils.newHashMap();
            map.put("id", e.getId());
            map.put("pId", e.getParentCode());
            map.put("label", StringUtils.getTreeNodeName(isShowCode, e.getOfficeCode(), e.getOfficeName()));
            mapList.add(map);
        }
        return mapList;
    }

프론트 데스크는 참고로 하겠습니다.https://www.cnblogs.com/dongyuxin/p/9429362.html#4095727수정을 했습니다.
프런트:
 
  
		     
		  


data() {
	      return {
	        value: null,
	        options: [{}], 
	      };
	    },  

//        
	         	this.$http.get('/f/dictData/officeListData').then(function(res){
	         		alert(JSON.stringify(res.body));
	         		this.options = this.toTreeData(res.body);
	         	
			  })

toTreeData(data,id,pid,name) {
	    	    //        ,            ,pId 1
	    	        let parent = [];
	    	        for (let i = 0; i < data.length; i++) {
	    	            if(data[i].pId !== "0"){
	    	            }else{
	    	              let obj = {
	    	                label: data[i].label,
	    	                id: data[i].id,
	    	                children: []
	    	              };
	    	              parent.push(obj);//      
	    	            }
	    	        }
	    	        children(parent);
	    	    //        ,         
	    	    function children(parent) {
	    	      if (data.length !== 0) {
	    	        for (let i = 0; i < parent.length; i++) {
	    	          for (let j = 0; j < data.length; j++) {
	    	            if (parent[i].id == data[j].pId){
	    	              let obj = {
	    	                label: data[j].label,
	    	                id: data[j].id,
	    	                children: []
	    	              };
	    	              parent[i].children.push(obj);
	    	            }
	    	          }
	    	          children(parent[i].children);
	    	        }
	    	      }
	    	    }
	    	    return parent;
	    	  }

좋은 웹페이지 즐겨찾기