惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
D
Docker
J
Java Code Geeks
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
腾讯CDC
罗磊的独立博客
U
Unit 42
爱范儿
爱范儿
Vercel News
Vercel News
MyScale Blog
MyScale Blog

博客园 - 泡面 @ 幸福

nodejs&wsl&vscode&docker开发环境搭建 python中list数组指定类型 windows10安装Trading View出错解决办法 windows or linux 64位安装ta-lib包 在centos7开启SSH服务 在centos7升级nodejs到最新版本 一张自画的RBAC用户、组、角色、权限、指令、资源图 JSON树形格式从子级获取所有父级ID MYSQL查询上级和下级 码云push时提示 DeployKey does not support push code fatal: Could not read from remote repository. git常用命令 thinkjs框架发布上线PM2管理,静态资源访问配置 登陆服务器提示“You need to run "nvm install N/A" to install it before using it.” CentOS 7.x 用shell增加、删除端口 CentOS 7.X 安全手记 Centos 7.x nginx隐藏版本号 centos7磁盘挂载及取消 CentOS 7.4上网速度慢,修改DNS! Centos7.4 安装Docker
JSON数据格式生成无限级树结构
泡面 @ 幸福 · 2020-01-27 · via 博客园 - 泡面 @ 幸福
buildTree(data, id, pid) {
    let map = {};
    data.forEach(function (item) {
      // map[item.id] = item; 
      eval('map[item.' + id + '] = item;')   //当前ID
    });
    let val = [];
    data.forEach(function (item) {
      // var parent = map[item.parent_group_id];      
      let parent = eval('map[item.' + pid + '];')     //上级ID
      if (parent) {
        (parent.children || (parent.children = [])).push(item);
      } else {
        val.push(item);
      }
    });
    return val;
  }

posted @ 2020-01-27 10:39  泡面 @ 幸福  阅读(501)  评论(0)    收藏  举报