let arr = [
{
key: "数据库",
title: "数据库",
isLeaf: false,
children: [
{
key: "mysql",
title: "mysql",
isLeaf: false,
children: [
{
key: "137",
title: "QPS",
isLeaf: true,
},
{
key: "146",
title: "MySQL进程信息",
isLeaf: true,
},
],
},
{
key: "oracle",
title: "oracle",
isLeaf: false,
children: [
{
key: "137",
title: "QPS",
isLeaf: true,
},
],
},
],
},
];
function mapTree(org) {
const haveChildren =
Array.isArray(org.children) && org.children.length > 0;
return {
text: org.title,
value: org.key,
children: haveChildren ? org.children.map((r) => mapTree(r)) : [],
};
}
let data = [];
data = arr.map((org) => mapTree(org));
console.log(data);
js树结构递归并修改
最新推荐文章于 2023-12-27 11:52:03 发布