I have two lists, the aggregation brings me the categories codes and the categories list brings all the categories that I have registered. I need to look up the categories in categories using the aggregation ids to create a new list only with this filter. In the case of categories that are daughters (children property) I need to put in this new list the parent category and the daughter category.
Example, in the case of id 22 (rubber hammer) I would have to display not only the rubber hammer but also your parents: tools and hammer.
var aggregation = [
{id: 1},
{id: 12},
{id: 22}
]
var categories = [
{
code: 1,
name: "papelaria",
children: [
{
code: 12,
name: "papel",
parentCode: 1,
children: []
},
{
code: 13,
name: "lapis",
parentCode: 1,
children: []
}
]
},
{
code: 2,
name: "ferramentas",
children: [
{
code: 21,
name: "martelo",
parentCode: 2,
children: [
{
code: 22,
name: "martelo de borracha",
parentCode: 21,
children: []
}
]
},
]
},
{
code: 3,
name: "móveis",
children: []
}
]