element ui tree 如何只获取前三级节点
data: [{
id: 1, label: '一级 1',
children: [{
id: 4,
label: '二级 1-1',
children: [{
id: 9,
label: '三级 1-1-1',
children: [{
id: 11,
label: '四级 1-1-1',
}
}, {
id: 12,
label: '三级 1-1-2'
}]
}]
},
回答:
/** * @description
* @param {*} data 树结构数据
* @param {number} [limit=3] 层级限制
* @param {number} [count=1]
* @return {*}
*/
function handleTreeData(data, limit = 3, count = 1) {
return data?.map((x) => ({
...x,
children: count < limit ? handleTreeData(x.children, limit, count + 1) : [],
}))
}
回答:
data.forEach(item => { item.children.forEach(i => {
i.children.forEach((_item, index, arr) => {
arr[index].children = [];
});
});
});
以上是 element ui tree 如何只获取前三级节点 的全部内容, 来源链接: utcz.com/p/936604.html