LearnFast.Ninja

Mustache loop array of objects

Example of loop over array of json objects.

Data - Items is array of objects.

var items =

[
      {
            title:
"Post 1",

            description: "This is example of post data.",

      },

      {
            title:
"Post 2",
            description:
"This is example of post data.",

      }

]


Server code (node.js, java etc)

homepage: {
      title:
'Home page',
      items: items
}


page.html (mustache)

<h1>{{homepage.title}}</h1>

<ul>
{{#homepage.items}}
     
<h1>{{title}}</h1>

      <div>{{description}}</div>

{{/homepage.items}}

</ul>



Tags

mustache

array objects json