PlayFramework, Scala for loop in view layer. How to get index value? -


this question has answer here:

i have loop in view tier of playframework application.

@for(art <- currentpage.getarticles()) {  } 

where method: getarticles() returns object of: list<articlei>.

i index value inside loop.

how can achive this?

i use play 2.2.6 java , eclipse ide.

the eclipse plugin play very bad. if work, think intelisense figure out on own.

you can index in way:

@for((art, index) <- currentpage.getarticles()) {   <p>element @index @art</p> } 

note: index starts 0, if want display 1 instead:

@for((art, index) <- currentpage.getarticles()) {   <p>element @{index+1} @art</p> } 

i hope, helps you...


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -