1
I have two lists, Aggregation brings me the codes of the categories and the list Categories brings all the categories I have registered. I need to search categories in categories using Aggregation ids to create a new list only with this filter. In the case of categories that are daughters (property Children) I need to put in this new list the parent and daughter category.
Example, in id 22 (rubber hammer) cado I would have to display not only the rubber hammer but also his 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: []
}
]
Give an example of output.
– Pablo Almeida
For example if I filter by id 22, which is from the rubber hammer item, I would have to return an array (or any other form) of the code objects 2, 21 and 22.
– Felipe Coelho
Right, but will this include the kids as well? What is the exact format of the output? Show the expected output for the example you gave. You can use the [Edit] button to add the details to the question.
– Pablo Almeida
Also, you already have some code and are giving problem or are wondering about the algorithm to be used?
– Pablo Almeida
I did the code but I couldn’t bring in three levels of category, and I don’t have that code anymore. Using the rubber hammer example the output can look like this: [ {code: 2, name: "tools"}, {code: 21, name: "hammer"}, {code: 22, name: "rubber hammer"} ]
– Felipe Coelho