我试图使每个表条目都有一个可以展开/折叠的隐藏行,因此我尝试使用迭代来分配 th:id
但这似乎不起作用。所有内容均已生成,但按下按钮时隐藏行不会展开。
知道为什么吗?或者还有其他解决方案/解决方法吗?
<tbody th:each="topic, iterStat : ${topics}">
<tr>
<td>
<button data-toggle="collapse" data-th-target="'#demo' + ${iterStat.count}"> +</button>
</td>
<td th:text="${topic.getId()}"></td>
<td th:text="${topic.getName()}"></td>
<td th:text="${topic.getDescription()}"></td>
</tr>
<tr>
<td colspan="6" class="hiddenRow">
<div class="accordian-body collapse" th:id="'demo' + ${iterStat.count}"> Lorem ipsum</div>
</td>
</tr>
</tbody>
最佳答案
这个 data-th-target="'#demo' + ${iterStat.count}"
将不起作用。 Thymeleaf 中的任何自定义属性都需要定义为:th:attr="data-th-target=|#demo${iterStat.count}|"
更新:
属性应该是data-target
而不是data-th-target
关于Spring Thymeleaf 折叠表 :id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47126668/