当前位置:网站首页>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
}
边栏推荐
- MIMO array 3D imaging technology based on mobile terminal
- OpenAtom OpenHarmony分论坛,今天14:00见!附大事记精彩发布
- 全校软硬件基础设施一站式监控 ,苏州大学以时序数据库替换 PostgreSQL
- It is thought-provoking: is syntax really important? Qiu Xipeng group proposed a powerful baseline for aspect based emotional analysis
- 文档智能多模态预训练模型LayoutLMv3:兼具通用性与优越性
- 一次跨域问题的记录
- C语言 2:求三数字最大值,求三数字中间值,编写程序步骤
- One stop monitoring of the software and hardware infrastructure of the whole university, and Suzhou University replaces PostgreSQL with time series database
- No Identifier specified for entity的解决办法
- Learning C language together: structure (2)
猜你喜欢

Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source

ASP. Net core dependency injection journey: 1. Theoretical concepts

最短移动距离和形态复合体的熵

How to assemble a registry

基于Spark封装的二次开发工程edata-base,介绍

想要一键加速ViT模型?试试这个开源工具!

Iptables prevent nmap scanning and binlog explanation

Solved syntaxerror: (Unicode error) 'Unicode scape' codec can't decode bytes in position 2-3: truncated

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

Set up Samba service
随机推荐
颜值爆表!推荐两款JSON可视化工具,配合Swagger使用真香
迭代次数的差异与信息熵
TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
迭代次数和熵之间关系的一个验证试验
Use of beautifulsoup
Compete for the key battle of stock users and help enterprises build a perfect labeling system - 01 live review
WEB服务如何平滑的上下线
The permission problem of Oracle operating openldap
antd table+checkbox 默认值显示
已解决SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated
Use__ slots__ And__ dict__ To save space (it's simply a qualitative leap, and leetcode's personal test is effective)
antd中table hover上去的背景色样式修改
Views, triggers and stored procedures in MySQL
Document intelligent multimodal pre training model layoutlmv3: both versatility and superiority
JVM -- Analysis of bytecode
黑白像素分布对迭代次数的影响
No identifier specified for entity solution
Using skills of word
MySQL日志管理、备份与恢复
如何创建一个带诊断工具的.NET镜像