赞
踩
toTree(data) {
let result = []
if (!Array.isArray(data)) {
return result
}
/*
data.forEach(item => {
delete item.children;
});
*/
let map = {};
data.forEach(item => {
map[item.id] = item;
});
data.forEach(item => {
let parent = map[item.pId];
if (parent) {
(parent.children || (parent.children = [])).push(item);
} else {
result.push(item);
}
});
return result;
},
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。