Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playframework 2 java iterate map in template

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

like image 677
alcudia25 Avatar asked May 31 '13 23:05

alcudia25


Video Answer


2 Answers

In a Play 2 template, you can iterate on a map using this syntax :

@(myMap: Map[Integer, MyObject])

@for((key, value) <- myMap){
  @key - @value
}
like image 73
mguillermin Avatar answered Nov 15 '22 05:11

mguillermin


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
}
like image 34
alcudia Avatar answered Nov 15 '22 05:11

alcudia