I have collection X
I iterate through it and write it like that:
<span th:each="a, stat : ${X}"
th:text="${X[__${stat.index}__].someProperty} + ','">
</span>
my other try was:
<span th:each="a, stat : ${X}" th:for="|a${stat.index}|"
th:text="${X[__${stat.index}__].someProperty} + ','">
</span>
unfortunately the output is the same.
the output in the span is:
test1, test2, test3,
I want the output to be:
test1, test2, test3
without the comma at the end. How can I achieve that?
Solution:
th:text
associated with an element type span
must not contain the '<' character.Code:
<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
use
<span th:each="a, iterStat : ${X}" th:text="!${iterStat.last} ? ${a} + ',': ${a}"></span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With