开发者

Grails each tag with iteration

开发者 https://www.devze.com 2023-03-08 06:17 出处:网络
Hey. How can i have a variable in each tag to be an iterator (for exam开发者_开发百科ple, first time run cycle takes value=1, second time value=2, and so on..The status attribute is what you are looki

Hey. How can i have a variable in each tag to be an iterator (for exam开发者_开发百科ple, first time run cycle takes value=1, second time value=2, and so on..


The status attribute is what you are looking for. See below:

<g:each collection=${books} var="abook" status="i">
    ${i}
</g:each>

if you call ${i} inside the each tag it will return the current iteration count.

Assuming the books collection contains 5 books, the output will be:

0
1
2
3
4
0

精彩评论

暂无评论...
验证码 换一张
取 消