M
M
microf2018-04-16 08:54:35
JavaScript
microf, 2018-04-16 08:54:35

How to display only the desired values ​​from json?

Good afternoon. There are two json files - one with ingredients, the second with recipes with the id of these same ingredients
Plunker

{
  "id":"1",
  "name": "Огурец"
},
{
  "id":"2",
  "name": "Помидор"
},

...
{
  "id":"1",
  "name": "Salat1",
  "recipe":["1","3","5"]
}

I load all this into a component using a service, but I want to display it on the screen, when the button is clicked, only one at a time - i.e. clicked "Salad 1" - got the ingredients of only this salad. In which direction to dig? There is no database. Use Pipes somehow? or make some other service that will pull out by id and form the desired stream?
Plunker

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2018-04-16
@Arik

Something like this?

ingridients.filter(ingridient => {
    return recipe.includes(ingridient.id);
}))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question