Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The whole list of the array from store isn't rendered

Why the whole list of the array from store isn’t rendered, I get only the title in the div, but not getting the country, price, etc, from the store.
https://codesandbox.io/s/html-template-forked-ywqs9r?file=/index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="styles.css" />
    <script type="”module”" src="./script.js"></script>
    <title>Vesna</title>
  </head>

  <body>
    <section class="content">
      <div class="content__mid" x-data="">
        <template x-for="item in $store.products.items" :key="item.id">
          <p class="content__mid-item" x-text="item.title"></p>
          <p class="content__mid-item" x-text="item.country"></p>
          <p class="content__mid-item" x-text="item.manufacturer"></p>
          <p class="content__mid-item" x-text="item.price"></p>
          <p class="content__mid-item" x-text="item.validDate"></p>
        </template>
      </div>
    </section>
  </body>
</html>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am not sure this is the right answer, I have never used Alpine.js. However, by searching for "Alpine js for loop examples", I noticed that it was using a wrapping div when it needed multiple tags in the loop.

Maybe its templating does not allow multiple children under <template>, sort of like React used to require a single element for a component.

<template x-for="item in $store.products.items" :key="item.id">
  <div>
    <p class="content__mid-item" x-text="item.title"></p>
    <p class="content__mid-item" x-text="item.country"></p>
    <p class="content__mid-item" x-text="item.manufacturer"></p>
    <p class="content__mid-item" x-text="item.price"></p>
    <p class="content__mid-item" x-text="item.validDate"></p>
  </div>
</template>

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading