当前位置:网站首页>Tree data conversion
Tree data conversion
2022-07-27 11:00:00 【No overtime at the front end】
/** * Tree data conversion * @param {*} data * @param {*} id * @param {*} pid */
export function treeDataTranslate (data, id = 'id', pid = 'parentId',order,istyyw,caseId) {
let res = []
let temp = {
}
for (let i = 0; i < data.length; i++) {
temp[data[i][id]] = data[i]
if(istyyw&&caseId){
if(data[i].pid==(caseId+"1")){
temp[data[i][id]]['_level'] = 1;
}
}
}
for (let k = 0; k < data.length; k++) {
if (temp[data[k][pid]] && data[k][id] !== data[k][pid]) {
if (!temp[data[k][pid]]['children']) {
temp[data[k][pid]]['children'] = []
}
if (!temp[data[k][pid]]['_level']) {
temp[data[k][pid]]['_level'] = 1
}
data[k]['_level'] = temp[data[k][pid]]._level + 1
if(istyyw){
data[k]['catalogLevel'] = data[k]['_level'];
}
temp[data[k][pid]]['children'].push(data[k])
} else {
data[k]['_level'] = 1;
if(istyyw){
data[k]['catalogLevel'] = 1;
}
res.push(data[k])
}
}
function orderFunc(a,b){
if(!a[order])a[order] = 0;
if(!b[order])b[order] = 0;
return a[order] - b[order];
}
function sortDataHandle(arr){
arr = arr.sort(orderFunc);
for(var i = 0;i<arr.length;i++){
if(arr[i].children&&arr[i].children.length){
arr[i].children = sortDataHandle(arr[i].children);
}
}
return arr;
}
if(order)res = sortDataHandle(res);
// console.log(res);
return res
}
边栏推荐
- The largest square of leetcode (violence solving and dynamic programming solving)
- Apache cannot start in phpstudy
- How to assemble a registry
- The difference between scalar, vector, matrix and tensor in deep learning
- 一次跨域问题的记录
- No identifier specified for entity solution
- 颜值爆表!推荐两款JSON可视化工具,配合Swagger使用真香
- 推导STO双中心动能积分的详细展开式
- Project team summer vacation summary 01
- ECCV 2022 | 同时完成四项跟踪任务!Unicorn: 迈向目标跟踪的大统一
猜你喜欢

Edata base, a secondary development project based on spark packaging, is introduced

Deep analysis: what is diffusion model?

Li Kou brush question 02 (sum of three numbers + sum of maximum subsequence + nearest common ancestor of binary tree)

flask_ Output fields in restful (resources, fields, marshal, marshal_with)

图片中非0值的数量对分类的影响

如何创建一个带诊断工具的.NET镜像

Customized modification based on jira7.9.2

A few simple steps to realize the sharing network for industrial raspberry pie

Codeforces Round #807 (Div 2.) AB

Alibaba mailbox web login turn processing
随机推荐
Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
Synaesthesia integrated de cellular super large-scale MIMO and high-frequency wireless access technology
树形数据转换
Detailed explanation of status code meaning
Shardingproxy sub database and table actual combat and comparison of similar products
YonBuilder赋能创新,用友第四届开发者大赛“金键盘奖”开启竞逐!
Codeforces Round #807 (Div 2.) AB
7z usage
A few simple steps to realize the sharing network for industrial raspberry pie
ECCV 2022 | 同时完成四项跟踪任务!Unicorn: 迈向目标跟踪的大统一
Apache cannot start in phpstudy
Pyqt5 rapid development and practice 4.2 QWidget
MySQL deadlock, pessimistic lock, optimistic lock
TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
IMG SRC is empty or SRC does not exist, and the picture has a white border
Mysql死锁、悲观锁、乐观锁
Research on synaesthesia integration and its challenges
JVM -- Analysis of bytecode
一起学习C语言:结构体(二)
推导重叠积分的详细展开式 STO overlap integrals