html - Thymeleaf:可点击的行

标签 html hyperlink thymeleaf

我想在 html + thymeleaf 中生成可点击的表格行,但我遇到了以下问题。据我所知,它无法用链接(a-tag)包装 tr 元素,因为表格只能 直接包含 tr-subtags。所以我必须包装每个 td-tag 的内容,但这些值是由 thymeleaf 动态创建的!

将每一行(将每一行的每个 td-tag 链接)链接到生成的 url 的最佳方法是什么?是否有一些 th:text - 前缀/后缀功能?

<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>

最佳答案

我不得不解决与 Tymeleaf 非常相似的问题,而且我还需要将请求参数从项目传递到 url,所以我这样解决了:

<tr th:each="item : ${itmes}" style="cursor: pointer"
     th:onclick="'javascript:rowClicked(\'' + ${item.someField} + '\');'">
    ...
    <td>Some data</td>
    ...
</tr>

然后以某种方式包含脚本:

<script>
    function rowClicked(value) {
        location.href = "/myurl?param=" + value;
    }
</script>

关于html - Thymeleaf:可点击的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27484706/

相关文章:

html - 知道为什么这两个盒子会偏移吗?

javascript - GetElementById src 标记中的值

java - JSP/Tomcat : Navigation system with sub-folders but one page

spring - 是否可以在 ${...} 表达式中传递 NULL 作为参数?

Java 列表到 Thymeleaf 表单输入

javascript - 如何使用 jQuery 通过 Id 找到一个特定的祖 parent 并通过某个类获取其特定 child 的值(value)

javascript - jQuery FadeIn 如何知道使用的显示模式?

html - 图片链接失效

javascript - 在 Chrome 和 IE 11 中将嵌入图像作为新选项卡打开

spring - 同时使用 Thymeleaf 和 JSP