当前位置:网站首页>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
}
边栏推荐
- IMG SRC is empty or SRC does not exist, and the picture has a white border
- 最短移动距离和形态复合体的熵
- 泰山OFFICE技术讲座:缩放比例与打开文件
- Customized modification based on jira7.9.2
- Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
- MySQL must know and know!!! Reading this article is enough!!!
- Your appearance is amazing! Two JSON visualization tools are recommended for use with swagger. It's really fragrant
- 全校软硬件基础设施一站式监控 ,苏州大学以时序数据库替换 PostgreSQL
- Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
- Use__ slots__ And__ dict__ To save space (it's simply a qualitative leap, and leetcode's personal test is effective)
猜你喜欢

Non progressive phenomena of entropy and morphology

Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)

TensorFlow笔记——基本函数及概念

Symmetric encryption and asymmetric encryption

The open source project Taier version 1.1 was officially released, and the list of new functions is fast

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

The difference of iteration number and information entropy

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

Shardingproxy sub database and table actual combat and comparison of similar products

TDengine 助力西门子轻量级数字化解决方案 SIMICAS 简化数据处理流程
随机推荐
[QNX hypervisor 2.2 user manual]9.9 logger
Shardingsphere kernel principle
Tensorflow notes - basic functions and concepts
Tdengine helps Siemens' lightweight digital solution simicas simplify data processing process
Camera switching
The second method of calculating overlapping integral
Use of parsel
tf.AUTO_ Function of reuse
Symmetric encryption and asymmetric encryption
学习笔记-微信支付
Application scenarios, key technologies and network architecture of communication perception integration
Iptables prevent nmap scanning and binlog explanation
图片中非0值的数量对分类的影响
Deep analysis: what is diffusion model?
Customized modification based on jira7.9.2
Google browser screenshot tips
7z usage
厉害了!VMware ESXi安装记录,附下载
Data types and variables
Kgdb debug kernel cannot execute breakpoints and kdb-22:permisson denied