1
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')
outworking:
{
"1": [
{
"idpai": 1,
"pai": "joao",
"mae": "maria",
"idfilho": 1,
"filho": "marcos"
},
{
"idpai": 1,
"pai": "joao",
"mae": "maria",
"idfilho": 2,
"filho": "joao"
}
]
}
As I am using lodash I am looking for something that can help me, my list comes duplicated like this because it is a relational bank, there is some other way to solve?