I have an array map with json objects in javascript, the map consists of a title and list items, for list item Amount i use add and minus button, to change values in Amount, how can i change the values in the html but for each one object only?
const outputHtml = matches => {
if (matches.length > 0) {
const lookUpItem = matches.map(match => `
<div class="foodInfo">
<h4 id="title">${match.foodDesc}</h4>
<small><span class="foodDetails">
<li>Protein: ${match.Protein} g</li>
<li>Calories: ${match.Calories} cals</li>
<li>Total Fat: ${match.Fat} g</li>
<li><button onclick="minus()" id="minus">-</button>
<span id="amount">Amount: <span id="amountNumber">${match.amount1}</span> / ${match.msreDesc1} </span>
<button onclick="add()" id="add">+</button> </li>
<button onclick="submit()" id="submit">Add to Diary</button>
</span></small>
</div>
`
).join('');
itemList.innerHTML = lookUpItem;
}
}
The json file is fetched with api url, here snippet of .json file
[
{
"foodDesc": "French baguette by Panera bread",
"foodId": 738220,
"Calories": "263,1578947",
"Fat": "1,75438596",
"amount1": "1",
"Protein": "8,77192982",
},
{
"foodDesc": "Broccoli cheddar by Panera bread",
"foodId": 738375,
"Calories": "300",
"Fat": "19",
"amount1": "1,5",
"Protein": "12",
},
{
"foodDesc": "Whole grain baguette by Panera bread",
"foodId": 738240,
"Calories": "245,6140351",
"Fat": "1,75438596",
"amount1": "1",
"Protein": "10,52631579"
}
]
In HTML looks like this