zoukankan      html  css  js  c++  java
  • Java给树加子节点个数统计

    通过后台实现

    private List<Photo> getChildren(Photo photo) {
            List<Photo> children = new ArrayList<>();
            if (!photoList.isEmpty()) {
                photoList.stream().filter(child -> photo.getId().equals(child.getParentId())).forEach(child -> {
                    List<Photo> tmp = getChildren(child);
                    child.setChildren(tmp);
                    if (tmp.isEmpty()) {
                        child.setLeaf(true);
                    }
                    Boolean leaf = photo.getLeaf();
                    Integer parentId = child.getParentId();
                    if(leaf == null){
                        Integer childNodes = photoDao.countChildNodes(parentId);
                        if (photo.getText().indexOf("(")==-1) {
                            photo.setText(photo.getText() + "(" + childNodes + ")");
                        }
                    }
                    children.add(child);
                });
            }
            return children;
        }

    效果如下

  • 相关阅读:
    数据库
    php
    123
    es5新增
    正则表达式
    cookie
    Event事件下
    事件对象
    dva框架的下拉菜单的父子关系
    dva框架的table表格---删除
  • 原文地址:https://www.cnblogs.com/Java-Starter/p/7735985.html
Copyright © 2011-2022 走看看