zoukankan      html  css  js  c++  java
  • 前端要求特殊格式怎么办 学这招!

    构建树结构

    前端要求特殊格式? 学这招解决大多前端 格式

    写这个可 给我恶心坏了都

    list套map,再套list???

    [{
        id: 1,
        label: '一级 1',
        children: [{
            id: 4,
            label: '二级 1-1',
            children: [{
                id: 9,
                label: '三级 1-1-1',
            }, {
                id: 10,
                label: '三级 1-1-2'
            }]
        }]
    }, {
        id: 2,
        label: '一级 2',
        children: [{
            id: 5,
            label: '二级 2-1'
        }, {
            id: 6,
            label: '二级 2-2'
        }]
    }, {
        id: 3,
        label: '一级 3',
        children: [{
            id: 7,
            label: '二级 3-1'
        }, {
            id: 8,
            label: '二级 3-2'
        }]
    }]
    

    没办法解决呗~

    public List<Map<String, Object>> getallWarningInformation() {
        List<Map<String, Object>> treeLists = new ArrayList<>();
        List<SysClassifyEntity> categoryList = sysClassifyDao.getWarningInformationById(0);
        if (null != categoryList && categoryList.size() > 0) {
            categoryList.forEach(item -> {
                Map<String, Object> itemMap = new HashMap<>();
                itemMap.put("id", item.getId());
                itemMap.put("label", item.getName());
                getTreeLists(itemMap, item.getId());
                treeLists.add(itemMap);
            });
        }
        return treeLists;
    }
    
    private void getTreeLists(Map<String, Object> pMap, Integer pid) {
        List<Map<String, Object>> itemLists = new ArrayList<>();
        List<SysClassifyEntity> categoryList = sysClassifyDao.getWarningInformationById(pid);
        if (null != categoryList && categoryList.size() > 0) {
            categoryList.forEach(item -> {
                Map<String, Object> itemMap = new HashMap<>();
                itemMap.put("id", item.getId());
                itemMap.put("label", item.getName());
                getTreeLists(itemMap, item.getId());
                itemLists.add(itemMap);
            });
            pMap.put("children", itemLists);
        }
    }
    
  • 相关阅读:
    帮助理解Docker,生动装逼介绍Docker
    Java 最常见 200+ 面试题 + 全解析
    CentOS7.0 yum安装 docker
    集合总结
    C#复习笔记
    match方法的使用
    偏函数
    通用装饰器
    装饰器修饰带参数的功能函数
    多个装饰器的使用
  • 原文地址:https://www.cnblogs.com/laowt/p/14465419.html
Copyright © 2011-2022 走看看