cnpm i -S array-to-tree
引入
import arrayToTree from "array-to-tree";
使用
const pidData = [
{ name: "aa", id: "1", pid: null },
{ name: "bb", id: 2, pid: 1 },
{ name: "cc", id: 3, pid: "" },
{ name: "dd", id: 4, pid: 3 },
{ name: "ee", id: 5, pid: "3" },
];
const result = arrayToTree(pidData, {
parentProperty: "pid",
customID: "id",
childrenProperty: "children",
});
console.log(result);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)