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

List not rendered using AlpineJS

Using AlpineJS I have the following HTML:

  <div x-data="glossary()">
    <dl>
      <template x-for="term in data.terms">
        <dt x-text="term.name"></dt>
        <dd x-text="term.definition"></dd>
      <template>
    </dl>
  </div>

And glossary is the following:

export default function glossary() {

  return {

    data: {
      terms: null   
    },

    init() {

      this.data.terms = [
        { name: "a", definition: "da" },
        { name: "b", definition: "db" }
      ]

    }

  }

}

When I run the code the list is not populated.

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

What am I missing?

>Solution :

I think there is an issue in your HTML code and your JS code is fine.

<div x-data="glossary()">
  <dl>
    <template x-for="term in data.terms">
      <dt x-text="term.name"></dt>
      <dd x-text="term.definition"></dd>
    </template>
  </dl>
</div>

The issue is in your template tag closing tag. Instead of<template>, you should use </template>.

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