胸腺th:每个在元素之间添加昏迷 [英] Thymeleaf th:each adding coma between elements
本文介绍了胸腺th:每个在元素之间添加昏迷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有收藏集X
我遍历它并像这样写它:
I iterate through it and write it like that:
<span th:each="a, stat : ${X}"
th:text="${X[__${stat.index}__].someProperty} + ','">
</span>
我其他的尝试是:
<span th:each="a, stat : ${X}" th:for="|a${stat.index}|"
th:text="${X[__${stat.index}__].someProperty} + ','">
</span>
不幸的是,输出是相同的.
unfortunately the output is the same.
范围中的输出为:
test1, test2, test3,
我希望输出为:
test1, test2, test3
,末尾没有逗号.我该如何实现?
without the comma at the end. How can I achieve that?
解决方案:
- 提防与元素类型
span
相关的属性th:text
的值不得包含'<'字符.
- Beware of The value of attribute
th:text
associated with an element typespan
must not contain the '<' character.
代码:
<span th:each="a, stat : ${X}"
th:text=" ${X[__${stat.index}__].someProperty} + (${stat.size-1 > stat.index}? ',':'') ">
</span>
推荐答案
Thymeleaf has an iteration property last
see the documentation here: http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#keeping-iteration-status
使用
<span th:each="a, iterStat : ${X}" th:text="!${iterStat.last} ? ${a} + ',': ${a}"></span>
这篇关于胸腺th:每个在元素之间添加昏迷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文