我有一组看起来像这样的对象。
var arr = [{'id':21 ,'name' : 'name 1' ,'vehiclename' : 'vehicle 1' ,'parentid' : 21},
{'id':21 ,'name' : 'name 1' ,'vehiclename' : 'vehicle 2' ,'parentid' : 21},
{'id':22 ,'name' : 'name 2' ,'vehiclename' : 'vehicle 1' ,'parentid' : 22},
{'id':22 ,'name' : 'name 2' ,'vehiclename' : 'vehicle 2' ,'parentid' : 22}]
我想将数组展开或分组,现在看起来像这样。
var arr = [{'id':21,
name: 'name 1'
vehicles : [{'vehiclename':'vehicle 1','parentid':21},
{'vehiclename':'vehicle 2','parentid':21}] },
{'id':22,
name: 'name 2'
vehicles : [{'vehiclename':'vehicle 1','parentid':22},
{'vehiclename':'vehicle 2','parentid':22}] }
}]
任何帮助,将不胜感激。