问题描述
限时送ChatGPT账号..我有一个表格和一个多行数据集.我不想跨越这个表的所有行.所以我创建了一个计数器,但在 if 条件下出现错误:
<table class="table"><th:block th:each="t_log : ${dataset.rows}" th:with="counter=${counter} + 1"><tr th:if="${counter <= 5 }"><td th:text="${t_log.title}"/><td th:if="${t_log.msg == '1'}" th:text="在线"/><td th:if="${t_log.msg == '0'}" th:text="离线"/></tr></th:block></tbody>我从这里看到了一个例子:
http://forum.thymeleaf/Displaying-an-iterable-of-n-items-in-rows-of-3-items-with-thymeleaf-td4025738.html
但我的计数器没有成功.
解决方案 试试这个 Thymeleaf 有一个内置的 count 属性.请参阅文档的 6.2 http://www.thymeleaf/doc/tutorials/2.1/usingthymeleaf.html 还签出第 4.9 节,您可能需要将 <=
更改为 le;
<table class="table"><th:block th:each="t_log,count : ${dataset.rows}"><tr th:if="${count <= 5 }"><td th:text="${t_log.title}"/><td th:if="${t_log.msg == '1'}" th:text="在线"/><td th:if="${t_log.msg == '0'}" th:text="离线"/></tr></th:block></tbody>I have a table and a multiline dataset. I do not want to span all the rows of this table. So I created a counter but I get an error at the if condition:
<div th:if="${dataset}" th:with="counter=0">
<table class="table">
<tbody>
<th:block th:each="t_log : ${dataset.rows}" th:with="counter=${counter} + 1">
<tr th:if="${counter <= 5 }">
<td th:text="${t_log.title}"/>
<td th:if="${t_log.msg == '1'}" th:text="Online"/>
<td th:if="${t_log.msg == '0'}" th:text="Offline"/>
</tr>
</th:block>
</tbody>
</table>
</div>
I have seen an example from here:
http://forum.thymeleaf/Displaying-an-iterable-of-n-items-in-rows-of-3-items-with-thymeleaf-td4025738.html
But my counter does not do the trick.
解决方案 Try this Thymeleaf has a built in count property. See 6.2 of the documentation http://www.thymeleaf/doc/tutorials/2.1/usingthymeleaf.html also checkout section 4.9 you may need to change <=
to le;
<div th:if="${dataset}">
<table class="table">
<tbody>
<th:block th:each="t_log,count : ${dataset.rows}">
<tr th:if="${count <= 5 }">
<td th:text="${t_log.title}"/>
<td th:if="${t_log.msg == '1'}" th:text="Online"/>
<td th:if="${t_log.msg == '0'}" th:text="Offline"/>
</tr>
</th:block>
</tbody>
</table>
</div>
这篇关于thymeleaf 显示表格的前 k 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
本文发布于:2023-04-30 14:09:38,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表格 thymeleaf
- 上一篇: 那些优秀论文是怎么写的?
- 下一篇: winhex数据恢复入门教程
发布评论