我正在生成一个使用thymeleaf的表格,它代表对象列表(小吃)。每份小吃都有许多与之相关的选票。我想对每个零食这样用户就可以选它的按钮,增加了其显示的计票结果,然后更新一次点击提交按钮在thymeleaf表中动态创建按钮
<table class="table table-striped">
<thead>
<tr>
<th>Snacks</th>
<th>Last Date Purchased</th>
<th>Votes</th>
<th>Up Vote</th>
</tr>
</thead>
<tbody>
<tr th:each="snack,iterStat : ${snacksuggested}">
<td th:text="${snack.name}"></td>
<td th:text="${snack.lastPurchaseDate}"></td>
<td th:text="${snack.votes}"></td>
<td>
<button class="btn btn-default" th:id="${'voteBtn_'+(iterStat.count -1)}" th:text="${snack.name} +' Vote'">Up Vote</button>
</td>
</tr>
</tbody>
</table>
- 我如何引用一个特定的小吃?
- 我在哪里放置javascript函数定义?
- 而我该如何更新按钮点击显示的投票计数?
PS。我正在使用弹簧
您可以添加一个初始额外的单元格按行存储计数器。零食对象没有ID? – cralfaro
让我解释我到目前为止对编辑问题所做的... –