我的#each循环在单独编写时都有效,但在一起时,我的网页的表体是空白的。我做错了什么?
<table class="table" class="text-center">
<thead>
<tr>
<th>Surname</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{#each surnames as |surname|}}
{{#each names as |name|}}
<tr>
<td>{{surname}}</td>
<td>{{name}}</td>
</tr>
{{/each}}
{{/each}}
</tbody>
</table>
答案 0 :(得分:0)
第二个循环的上下文在嵌套时会发生变化。使用../
访问父作用域。
<table class="table" class="text-center">
<thead>
<tr>
<th>Surname</th>
<th>Name</th>
</tr>
</thead>
<tbody>
{{#each surnames as |surname|}}
{{#each ../names as |name|}}
<tr>
<td>{{surname}}</td>
<td>{{name}}</td>
</tr>
{{/each}}
{{/each}}
</tbody>
</table>