I'm using NodeJS, Handlebars & Bootstrap to build a simple webapp. It should loop through a MongoDB collection of mock products and display it's fields.
I'm displaying the data in "product cards" (refer to image). When looping through the collection to create the cards it's reading each Product fine however, I have a button which opens a modal on each card - which should display the info related to that product, this doesn't work.
The issue is that all the modals display info related to only the first index in the MongoDB collection.
Here is my HTML code to display the products:
<div class="products">
<h1>Featured Products</h1>
<section class="product-list">
<div class="product-container">
{{#each Product}}
<div class="card">
<div class="title">{{this.name}}</div>
<div class="image">
<img src="https://source.unsplash.com/random/50×50/?fruit" />
</div>
<div class="cost">{{this.cost}}</div>
<div>
<button class="buy-button">Add to cart</button>
<button
class="buy-button"
data-toggle="modal"
data-target=".bd-example-modal-sm"
>More Detail</button>
</div>
</div>
<!-- modal -->
<div
class="modal fade bd-example-modal-sm"
data-toggle="modal"
aria-hidden="true"
>
<div class="modal-dialog modal-md">
<div class="modal-content">
<div class="carousel" data-ride="carousel">
<div class="parentSlider">
<div class="parentSlider-cell">
<img
class="img"
src="https://source.unsplash.com/random/50×50/?fruit"
/>
</div>
<div class="product-detail-text">
<p>Name: {{this.name}}</p>
<p>Price: {{this.cost}}</p>
<p>Description: {{this.description}}</p>
</div>
</div>
</div>
<div class="modal-footer">
<button class="buy-button" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{{/each}}
</div>
</section>
</div>