BENBUN Coder
BENBUN Coder

Reputation: 4881

Looping in Handlebars

I am struggling to see how to use Handlebars with simple string arrays. I have the following object

enter image description here

When looping around the searchParam array I use something like :

  {{#each model.searchParam}}
  <table class="table table-bordered table-striped">
    <thead>
      <tr>
        <th class="th-narrow">Property</th>
        <th>Value</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><span class="label">name</span></td>
        <td>{{name}}</td>
      </tr>
      <tr>
        <td><span class="label">type</span></td>
        <td>{{type}}</td>
      </tr>
    </tbody>
  </table>
  {{/each}}

In the image above, how do I loop around the "searchInclude" array?

{{#each model.searchInclude}}
 ... wht do I reference here for the contents of the array? 
{{/each}}

Upvotes: 1

Views: 219

Answers (1)

MarcoL
MarcoL

Reputation: 9989

In case of an array, this will be the value and you can obtain the index with the Handlebar magic keyword @index

{{#each model.searchInclude}}
  {{@index}}: {{this}}
{{/each}}

Upvotes: 1

Related Questions