easyui Tree实现思路

 @RequestMapping("/typeClassifyTree") 
     public void classifyTree(HttpServletRequest request,HttpServletResponse response,String planId) throws Exception {
         List<TreeDataString> list=new ArrayList<TreeDataString>();
         SessionInfo session=getCurrentSessionInfo(request);
         List<TrainplanClassifyInfo> data=trainplanClassifyService.getTrainplanClassifyListByPlatFormId(session.getPlatFormId());
         Map<Long, Long> map = new HashMap<Long, Long>();
         
         for(TrainplanClassifyInfo tt:data){
             if(Objects.equals("0", tt.getParentId())) {
                 TreeDataString node=new TreeDataString();
                 node.setText(tt.getName());
                 node.setId(tt.getId());
                 node.setChildren(new ArrayList<TreeDataString>());
                 node.setLevel(Integer.valueOf(tt.getParentId()));
                 TrainplanLmsInfo t=new TrainplanLmsInfo();
    t.setId(planId);
                 map = MapUtils.list2TreeMap1(trainplanLmsService.findByParam(t,null), "classifyId", "id");
                 if(map.containsKey(tt.getId())){
                node.setChecked(true);
                 }
                 getTreeDataClassify(data,node,map); 
                 list.add(node);
             }
         }
         
             writeJson(response, list);
        

     }


//

 private void getTreeDataClassify(List<TrainplanClassifyInfo> list, TreeDataString tree, Map<Long, Long> map) {
         List<TrainplanClassifyInfo> tmpList = findChildrenClassify(list, tree);
         if(tmpList.size()>0){
        for (TrainplanClassifyInfo item : tmpList) {
        TreeDataString td = null;
        td = new TreeDataString(item.getId(), item.getName(), "open", new Attributes(item.getName(), null, false), new ArrayList<TreeDataString>(),map.containsKey(item.getId()));
        getTreeDataClassify(list, td, map);
        tree.setAttributes(new Attributes(tree.getText(), null, true));
        tree.getChildren().add(td);
        }
         }
     }

//

 private List<TrainplanClassifyInfo> findChildrenClassify(List<TrainplanClassifyInfo> mList, TreeDataString tree) {
         List<TrainplanClassifyInfo> childInfoList = new ArrayList<TrainplanClassifyInfo>();
         for (TrainplanClassifyInfo t : mList) {
             if (tree.getId().equals(t.getParentId())) {
                 childInfoList.add(t);
             }
         }
         return childInfoList;
     }

//

public String id;
public String text;
// 状态:open 或者 closed
public String state;
public boolean checked;
private Integer level;

public Attributes attributes;

public TreeDataString(){}


public TreeDataString(String id, String name, String state, Attributes attributes, ArrayList<TreeDataString> arrayList, boolean flag) {
this.id=id;
this.text=name;
this.state=state;
this.attributes=attributes;
this.children=arrayList;
this.checked=flag;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值