I have this data structure:
flavors": {
"sour": 0.16666666666666666,
"salty": 0.16666666666666666,
"sweet": 0,
"meaty": 0.16666666666666666,
"bitter": 0.16666666666666666
}
My html is this:
<p>Flavors:</p>
<ul>
{{#Flavors}}
<li>{{Flavours.Name}}</li> // doesn't work //
{{/Flavors}}
</ul>
What I'm trying to do is get at the name of the flavour: i.e. salty, sour, etc. I want to be able to cater for arbitrary values is the JSON, and not code them in the html block.
You may iterate over the object in this way:
{{#each myObject}}
Key: {{@key}} Value = {{this}}
{{/each}}
For details check this post: Handlebars/Mustache - Is there a built in way to loop through the properties of an object?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With