Thymeleaf:可点击的行 [英] Thymeleaf: clickable row
问题描述
我想在html +百里香内生成可点击的表格行,但是我有以下问题. AFAIK它不能用链接(一个标签)包装一个tr元素,因为一个表只能 直接包含tr子标签.因此,我必须包装每个td标签的内容,但是这些值是由百里香叶动态创建的!
I want to generate clickable table rows within html + thymeleaf, but I have the following problem. AFAIK it's not able to wrap a tr element with a link (a-tag), because a table can only directly contain tr-subtags. So I have to wrap the content of each td-tag, but these values are dynamically created by thymeleaf!
将每一行(链接每一行的每个td标签)链接到生成的URL的最佳方法是什么?有一些th:text-前缀/后缀功能吗?
What would be the best approach to link each row (link each td-tag of each row) to a generated url? Is there some th:text - prefix/suffix functionality?
<tr th:each="item : ${itmes}">
<td th:text="${{item.name}}">some name</td>
<td th:text="${{item.date}}">01.03.2014</td>
<td>author</td>
<td>2</td>
<td>
<a th:href="@{/backend/items/{id}(id=${item.id})}" href="show.html"
role="button" class="btn btn-default btn-circle">
<i class="fa fa-info"></i>
</a>
<a th:href="@{/backend/items/{id}/update(id=${item.id})}" role="button" class="btn btn-warning btn-circle">
<i class="fa fa-edit"></i>
</a>
</td>
</tr>
推荐答案
做到这一点的最简单的方法是使用javascript创建可点击的每一行.
The least problematic way to do this is using javascript to create each row clickable.
例如
$("#yourtablename tr").click(function() {
//do more javascript code to meet your needs
});
我个人将href附加到tds之一上,然后执行以下操作:
Personally i would attach a href to one of the tds then do something like below:
$("#yourtablename tr").click(function() {
window.location = $(this).find('td:eq(5)').attr("href");
});
希望有帮助
这篇关于Thymeleaf:可点击的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!