[英]How Do I Render Table With Meteor Spacebars Template and Row Number For Each Row?
如何在模板中呈現帶有流星空格鍵{{#each}}
的表格,並為每一行在第一列中添加行號,如下所示:
| | 標題標題| 內容標題|
| 1 | 第一個標題| 第一內容|
| 2 | 第二標題| 第二內容|
| 3 | 第三標題| 第三內容|
這是我現在的每個代碼:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th></th>
<th>title</th>
<th>content</th>
</tr>
</thead>
<tbody>
{{#each posts}}
<tr>
<td>
*** need index for each row in this column ***
</td>
<td>
{{ title }}
</td>
<td>
{{ content }}
</td>
</tr>
{{/each}}
</tbody>
</table>
有沒有一種方法可以在{{#each}}
獲取數組索引,或者在每次迭代中定義名為index
self和index++
額外屬性?
在返回值的游標的幫助器中,不只是執行collection.find()
而是執行collection.find().fetch()
這將為您提供對象數組而不是游標。 然后只需通過.forEach()
來添加索引鍵! 或者,您可以只使用collection.map()
並將鍵映射到數組中時直接將鍵添加到每個元素。 文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.