下载
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);
到此这篇关于Vue将将后端返回的list数据转化为树结构的文章就介绍到这了,更多相关Vue将将后端返回的list数据转化为树结构内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!