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; }