I'm trying to get the following result using lodash:
[
{
"idpai": 1,
"pai": "joao",
"mae": "maria",
"filhos": [
{"id": 1, "nome": "joaozinho"},
{"id": 2, "nome": "pedrinho"}
]
}
]
with the following code:
var lista = [
{idpai: 1, pai: 'joao', mae: 'maria', idfilho: 1, filho: 'marcos'},
{idpai: 1, pai: 'joao', mae: 'maria', idfilho: 2, filho: 'joao'},
]
result = _.groupBy(lista, 'idpai')
result:
{
"1": [
{
"idpai": 1,
"pai": "joao",
"mae": "maria",
"idfilho": 1,
"filho": "marcos"
},
{
"idpai": 1,
"pai": "joao",
"mae": "maria",
"idfilho": 2,
"filho": "joao"
}
]
}
As I'm using lodash I'm looking for something that can help me, my list comes duplicated because it's a relational database, is there any other way to solve it?