• 树状结构 父子节点 递归 recursion n级 树


    树形控件 Tree - Ant Design https://ant-design.gitee.io/components/tree-cn/

    function dig(path = '0', level = 3) {
      const list = [];
      for (let i = 0; i < 10; i += 1) {
        const key = `${path}-${i}`;
        const treeNode = {
          title: key,
          key,
        };
    
        if (level > 0) {
          treeNode.children = dig(key, level - 1);
        }
    
        list.push(treeNode);
      }
      return list;
    }

      console.log(dig("0",4))

    456
    <script>
        const permissionData = [
            {
                "title": "水果",
                "key": 90101,
                "children": [
                    {
                        "title": "用户管理",
                        "key": 90100,
                        "children": [
                            {
                                "title": "用户管理查看",
                                "key": 90110
                            },
                            {
                                "title": "添加",
                                "key": 90111
                            },
                            {
                                "title": "修改",
                                "key": 90112
                            },
                            {
                                "title": "删除",
                                "key": 90113
                            }
                        ]
                    }
                ]
            },
            {
                "title": "蔬菜",
                "key": 1,
                "children": [
                    {
                        "title": "用户管理",
                        "key": 2,
                        "children": [
                            {
                                "title": "用户管理查看",
                                "key": 3
                            },
                            {
                                "title": "添加",
                                "key": 4
                            },
                            {
                                "title": "修改",
                                "key": 5
                            },
                            {
                                "title": "删除",
                                "key": 6
                            }
                        ]
                    }
                ]
            },
            {
                "title": "大米",
                "key": 7,
                "children": [
                    {
                        "title": "用户管理",
                        "key": 8,
                        "children": [
                            {
                                "title": "用户管理查看",
                                "key": 9,
                                "children": [
                                    {
                                        "title": "99用户管理查看",
                                        "key": 99
                                    },
                                    {
                                        "title": "9添加",
                                        "key": 911
                                    }
                                ]
                            },
                            {
                                "title": "添加",
                                "key": 11,
                                "children": [
                                    {
                                        "title": "11用户管理查看",
                                        "key": 119
                                    },
                                    {
                                        "title": "添加",
                                        "key": 1111
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    
        let PermissionRootMap = {};// 建立映射:所有权限对应的根权限的值
    
        const GetPermissionRootMap = () => {
            console.log("IN GetPermissionRootMap");
            permissionData.forEach(p1 => {
                // 注意原始数据为列表,第一次循环,可以获取rootKey;在递归时使用
                const rootKey = p1.key;
                let R = (obj) => {
                    PermissionRootMap[obj.key] = rootKey;
                    let children = obj.children;
                    if (children) {
                        children.forEach(p2 => {
                            R(p2)
                        });
                    }
                }
                R(p1);
            });
            console.log("ret ", PermissionRootMap);
        };
        GetPermissionRootMap();
    </script>
    

      

     树形控件 Tree - Ant Design https://ant.design/components/tree-cn/

    let PermissionRootMap = {};// 建立映射:所有权限对应的根权限的值

    const GetPermissionRootMap = () => {
      console.log("IN GetPermissionRootMap");
      permissionData.forEach(p1 => {
        // 注意原始数据为列表,第一次循环,可以获取rootKey;在递归时使用
        const rootKey = p1.key;
        let R = (obj) => {
          PermissionRootMap[obj.key] = rootKey;
          let children = obj.children;
          if (children) {
            children.forEach(p2 => {
              R(p2)
            });
          }
        }
        R(p1);
      });
      console.log("ret ", PermissionRootMap);
    };

    三级商品类目树

  • 相关阅读:
    使用 %matplotlib inline 出错?
    RandomForest 调参
    sql中的笛卡尔积
    Sublime text 3 搭建Python3 IDE
    在Windows Python3.5 安装LightGBM
    lodash获取数组或对象的值 at
    lodash 移除数据元素 pull without 删除数组元素
    js 常用类型转换简写
    UTC时间格式转换
    CSS Flexible 布局兼容性以及解决方案
  • 原文地址:https://www.cnblogs.com/rsapaper/p/15923586.html
Copyright © 2020-2023  润新知