Reputation: 71
I'm new in playframework 2 and I would like to iterate a map in the template, I'm using java for the moment :-) Can anybody, please, write a example ? My map is like :
Map<Integer,MyObject>
Thanks in advance
Upvotes: 6
Views: 3990
Reputation: 131
Thank a lot for your answer @mguillermin. I found other thing that can help somebody, to use the current index in the loop :
@for(((key, value), currentIndex) <- myMap.zipWithIndex) {
@key - @value - @currentIndex
}
Upvotes: 8
Reputation: 4181
In a Play 2 template, you can iterate on a map using this syntax :
@(myMap: Map[Integer, MyObject])
@for((key, value) <- myMap){
@key - @value
}
Upvotes: 15