3
Associating the object "categories" in "products"; With the ID I need to associate to such product, so for example "products 1" should receive the "categories" with the ID [1, 3, 4]. creating another array combining the data between these objects.
{
"produtos": [{
"id": 1,
"nome": "Produto 1",
"categorias": [1, 3, 4]
}, {
"id": 2,
"nome": "Produto 2",
"categorias": [1, 2, 5]
}, {
"id": 3,
"nome": "Produto 3",
"categorias": [3, 1, 4]
}],
"categorias": [{
"id": 1,
"nome": "Categoria 1"
}, {
"id": 2,
"nome": "Categoria 2"
}, {
"id": 3,
"nome": "Categoria 3"
}, {
"id": 4,
"nome": "Categoria 4"
}, {
"id": 5,
"nome": "Categoria 5"
}]
}
Result array: { "products": [ { "id": 1, "name": "Product 1", "categories": [ {"id" : 1, "name" : "Category 1"}, {"id" : 3, "name" : "Category 3"}, {"id" : 4, "name" : "Category 4"} ] } ]
Can you explain better what’s in the title? It’s unclear what you want to do...
– Sergio
With object "categories" in "products" with the ID I need to associate to such product, so for example "products 1" should display the "categories" with the ID [1, 3, 4].
– Marco Aurélio
It’s still unclear... Can you make [Edit]ar on the question and add more info? I don’t understand what you mean by "should show" and "with filter". Want to generate HTML or create another array combining the data this object?
– Sergio
You can add an example of what the final result should look like?
– Sergio
@Sergio, I made the change, it’s something like associating the object categories to the object products, where I have the ID of the categories of which will be combined
– Marco Aurélio