PanosCool
PanosCool

Reputation: 185

How to select a category from a json file with a dropdown list

Im trying to select a category from a json file and use it to show the representing value of that category.

{
 "truth": [
   {
     "id": "dd33b9c4-c3ef-11e8-b8dc-8b77bf3680b2",
     "value": "bla bla",
     "category": "funny",
     "appeared": false
   }
  ]
 "dare": [
   {
     "id": "dd33b9c4-c3ef-11e8-b8dc-8b77bf3680b2",
     "value": "bla bla",
     "category": "funny",
     "appeared": false
   }
  ]
 } 

<select>
   <option value={[truth].category}></option>
</select>

Thanks for the help.

Upvotes: 0

Views: 432

Answers (2)

Torsten Barthel
Torsten Barthel

Reputation: 3458

I would suggest to use Angular or a different library to accomplish this. Take a look at following: Angular

With the help of this frontend HTTP library you are able to build UI's based on HTML and connect them to the data model thats in your case the JSON object.

Upvotes: 0

Japesh
Japesh

Reputation: 261

You have to use index of object that you are trying to access in truth array like this

truth[0].category

Upvotes: 1

Related Questions