谷粒商城-品牌管理-关联分类中新增关联选取不了数据,如图点手机还有下一级。

照着谷粒商城做什么都没错为什么错在这种一脸懵的bug上,为什么视频展开到最后一级手机就可以选择手机,为什么我的最后一级手机还可以展开啊?
心态大蹦

img

改成这样就行了:

private List<PmsCategory> getChildren(PmsCategory root, List<PmsCategory> all) {
        List<PmsCategory> children = all.stream().filter(categoryEntity -> {
            // 找到当前id的子菜单
            return categoryEntity.getParentCid().equals(root.getCatId());
        }).map(categoryEntity -> {
            // 1 找到子菜单,递归找法
            List<PmsCategory> res = getChildren(categoryEntity, all);
            if(res==null||res.size()==0){
                categoryEntity.setChildren(null);
            }else{
                categoryEntity.setChildren(res);
            }
//            categoryEntity.setChildren(getChildren(categoryEntity, all));
            return categoryEntity;
        }).sorted((menu1, menu2) -> {
            // 2 菜单排序
            return menu1.getSort() - menu2.getSort();
            // menu1.getSort()==null?0;menu1.getSort()
        }).collect(Collectors.toList());
        return children;
    }

那个==改成equals是idea提示包装类应采用equals比较相等,不改也不报错

最后一层也是空数组或者空集合,这个级联的方式应该是采用了递归的思想,建议在对应的方法里面加上一个·if判断如果某选项没有子分类则结束该项的递归,可以通常长度来判断,看看他的下级长度是否等于0,如果数据是写死的,那么去掉那个空即可

可能是你最后一层还嵌套一个空数组,把这个空数组去了就可以了