json数据按照某一个相同键值进行分类成一个新的二维json数组

复制代码
 1     formatTreeData(checkNodes){
 2       var map = {},
 3           targetData = [];
 4       checkNodes.forEach(item => {
 5         if (!map[item.groupKey]) {
 6           targetData.push({
 7             value: item.groupKey,
 8             label:item.groupName,
 9             children: [item]
10           });
11           map[item.groupKey] = item;
12         } else {
13           for (var j = 0; j < targetData.length; j++) {
14             var dj = targetData[j];
15             if (dj.value === item.groupKey) {
16               dj.children.push(item);
17               break;
18             }
19           }
20         }
21       })
22       return targetData
23     },
View Code
复制代码

 

posted @   醒日是归时  阅读(42)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示