Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

Get JSON data by ID

$
0
0

I’m trying to get data from a particular ID in a JSON file.

The JSON set-up is:

{
    "items": [
      {
      "id":"0",
      "link": "/music",
      "title": "Music",
      "area": "Devon",
      "type": "place",
      "image": ""
    },
    {
       "id":"1",
      "link": "/festivals",
      "title": "Festivals",
      "area": "Cornwall",
      "type": "event",
      "image": ""
    },

Each page needs to get different data. So far I have done this (page.ts) which gets all the json data

 this.http.get('assets/events.json').subscribe(res => {
      this.information = res['items']

But I need to add a filter to get the ID and then get the data from that ID only. I found this (below) but have no idea how to implement it.

 const index = this.information.findIndex(item => item.id === 8);

Any help appreciated

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles