thymeleaf 显示表格的前 k 行 [英] thymeleaf show top-k rows of a table
本文介绍了thymeleaf 显示表格的前 k 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格和一个多行数据集.我不想跨越这个表的所有行.所以我创建了一个计数器,但在 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>我从这里看到了一个例子:
但我的计数器没有成功.
解决方案 试试这个 Thymeleaf 有一个内置的 count 属性.请参阅文档的 6.2 http://www.thymeleaf.org/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:
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.org/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屋!
查看全文
登录
关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆