How to iterate over array in handlebar template without defined name in model

jmav picture jmav · Jul 27, 2012 · Viewed 9.9k times · Source

I have model:

[
  {
    "ID": 5,
    "email": "[email protected]"
  },
  {
    "ID": 6495,
    "email": "[email protected]"
  }
]

Code for iterating in handlebars:

   {{#each xxx}}
    <p>{{email}}</p>
   {{/each}}

how do I define xxx ?

If JSON had name in model like:

   users: [
      {
        "ID": 5,
        "email": "[email protected]"
      },
      {
        "ID": 6495,
        "email": "[email protected]"
      }
    ]

I would simple iterate in handlebars like:

   {{#each users}}
    <p>{{email}}</p>
   {{/each}}

Answer

Dave Stibrany picture Dave Stibrany · Jun 26, 2013

This works too:

{{#each this}}
<p>{{email}}</p>
{{/each}}