var first = d.filter(e=> !!!e.pId);
var last = d.filter(e=> !!!e.id);
var map = {};
var idMap = {};
d.forEach(d => {
idMap[d.id] = d;
if(map[d.pId]) {
map[d.pId].push(d);
}else{
map[d.pId] = [d];
}
});
console.log(JSON.parse(JSON.stringify(map)));
for(var key in map) {
if(idMap[key]) {
// console.log("get children", key)
idMap[key]['children'] = map[key];
delete map[key];
}
}
console.log(map);