//树结构
const treeData = [
{
value: '主目录',
id: '0-0',
level: 1,
children: [
{
value: '子目录一',
id: '0-0-0',
children: [
{
value: '孖一',
id: '0-0-0-0',
children: [{
value: '子子子子',
id: '0-0-0-0-0',
children: [{
value: '哈哈哈',
id: '0-0-0-0-0-1',
}]
}]
},
{
value: '孖二',
id: '0-0-0-1',
},
],
},
{
value: '子目录2',
id: '0-0-1',
children: [{ value: '子目录2-2', id: '0-0-1-0' }],
},
{
value: '子目录3',
id: '0-0-3',
children: [
{ value: '子目录3-2', id: '0-0-2-0' },
{ value: '子目录3-3', id: '0-0-2-1' },
],
},
],
},
{
value: '目录2',
id: '0-1',
children: [
{
value: '子目录8098',
id: '0-1-3',
children: [
{ value: '子目录00-2', id: '0-1-2-0' },
{ value: '子目录90-3', id: '0-1-2-1' },
],
},
],
},
];
//递归
const renderTree = (data, level) => {
return data.map((item) => {
item.level = level;
if (item.children) {
renderTree(item.children, level + 1);
}
});
};
renderTree(treeData, 1);
console.log('treedata=>',treeData);
网友评论