标签:tree return parent reac func eva map ret for
buildTree(data, id, pid) { let map = {}; data.forEach(function (item) { // map[item.id] = item; eval(‘map[item.‘ + id + ‘] = item;‘) //当前ID }); let val = []; data.forEach(function (item) { // var parent = map[item.parent_group_id]; let parent = eval(‘map[item.‘ + pid + ‘];‘) //上级ID if (parent) { (parent.children || (parent.children = [])).push(item); } else { val.push(item); } }); return val; }
标签:tree return parent reac func eva map ret for
原文地址:https://www.cnblogs.com/aipeli/p/12235498.html