Vue list数据转化为树结构
~疆 人气:0下载
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);
加载全部内容