simple loop in thymeleaf

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

simple loop in thymeleaf

eiryu
Is simple loop in thymeleaf below correct? Are there any other standard way?

<select>
  <option th:each="i, iStat : ${#numbers.sequence(1, __#{buy.max}__)}" th:value="${i}" th:text="${i}+ '個'"></option>
</select>
Reply | Threaded
Open this post in threaded view
|

Re: simple loop in thymeleaf

Zemi
Administrator
You usually iterate over a Collection or array, so the syntax becomes clearer, like:

  <option th:each="foo : ${fooList}"
              th:value="${foo.id}" th:text="${foo.label}">My option</option>

In your example, the variable iStat is unused, so you could remove it.

  <option th:each="i : ${#numbers.sequence(1, __#{buy.max}__)}"
              th:value="${i}" th:text="${i}+ '個'"></option>

Reply | Threaded
Open this post in threaded view
|

Re: simple loop in thymeleaf

eiryu
This post was updated on .
Thank you for your reply.
I know "iterate over collection or array", but simple loop like "for statement" don't.
I think simple loop using "${#number.sequence(from,to)}" should be written to a manual if this way is a standard.(Now, it is written only to the appendix.)