我很难看到如何使用Handlebars和简单的字符串数组。我有以下对象
在搜索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}}
答案 0 :(得分:1)
如果是数组,this
将是值,您可以使用Handlebar magic关键字@index
获取索引
{{#each model.searchInclude}}
{{@index}}: {{this}}
{{/each}}