在车把上循环

时间:2014-03-11 09:08:33

标签: handlebars.js

我很难看到如何使用Handlebars和简单的字符串数组。我有以下对象

enter image description here

在搜索searchParam数组时,我使用类似的东西:

  {{#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}}

在上图中,我如何循环“searchInclude”数组?

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

1 个答案:

答案 0 :(得分:1)

如果是数组,this将是值,您可以使用Handlebar magic关键字@index获取索引

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