方法一
flat2StructureArray(arr) {
return arr.filter((father) => {
let children = arr.filter((child) => father.ID == child.PID);
children.length > 0 &&(father.children = children);
return father.PID == '';
})
}
方法二
flatArray2TreeArrayByPID(arr) {
const r = [], map = {};
arr.forEach(v => map[v.ID] = v);
arr.forEach(v => {
const p = map[v.PID || v.pid || v.parentId];
(p ? p.children || (p.children = []) : r).push(v);
})
return r;
},