I'm puzzled as to why I am unable to execute the for loop using Alpine.js and dynamically display the title of each item. I have attempted to utilize the store within the script HTML tag in order to iterate over an array of objects and retrieve the title key of each object.
// html
<div class="content__mid" x-for="item in $store.products.items" :key="item.id">
<p class="content__mid-item" x-text="item.title"></p> // the content is currently empty
</div>
<script>
document.addEventListener('alpine:init', () => {
Alpine.store('products', {
items: [
{
id: 1,
title: 'Aspirin',
country: 'USA',
manufacturer: 'Bangladesh',
price: '120',
validDate: '02.10.2024'
},
{
id: 2,
title: 'Aspirin',
country: 'Italy',
manufacturer: 'Bangladesh',
price: '120',
validDate: '02.10.2024'
},
{
id: 3,
title: 'Aspirin',
country: 'Austria',
manufacturer: 'Bangladesh',
price: '140',
validDate: '02.10.2024'
}
],
})
})
</script>