Thymeleaf 循环直到一个数字 [英] Thymeleaf Loop Until a Number
本文介绍了Thymeleaf 循环直到一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 Thymeleaf 进行搜索并从服务器获得响应.这保存了结果的数量:
I make a search and get response from server with Thymeleaf. This holds the number of results:
${response.count}
我想进行这样的迭代:
for (int i = 1; i <= response.count; i++) {
if (response.page == i) {
<button class="active">Dummy</button>
} else {
<button>Dummy</button>
}
}
我该怎么做?我试过这样的事情:
How can I do that? I've tried something like that:
${#numbers.sequence(0, response.count)}
但是没有用.
我试过了,但也没有用:
I've tried that but didn't work too:
<button th:each="i: ${#numbers.sequence(0, response.count - 1)}" th:class="${i == response.page} ?: active">Dummy</button>
推荐答案
这对我有用:
<th:block th:each="i: ${#numbers.sequence(0, response.count - 1)}">
<button th:if="${response.page == i}" class="active">Dummy</button>
<button th:unless="${response.page == i}">Dummy</button>
</th:block>
这篇关于Thymeleaf 循环直到一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文