alcudia25
alcudia25

Reputation: 71

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

Upvotes: 6

Views: 3990

Answers (2)

alcudia
alcudia

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

mguillermin
mguillermin

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

Related Questions