Question

I'm trying to iterate over a List with Person objects to build a table. Each row is a Person entry. A Person has some general infos like name e.g. - and an ID. I need all IDs concatenated as String to call another function (wich will export those Persons to CSV).

So what I try to achieve is a variable inside the iteration to concatenate with all IDs like 12,13,14,346,74,12to pass over to the href="/export?ids=@ids

@for(person <- personList) {
 <tr><td>@person.name</td></tr>
}

Inside this loop I need to concantenate all @person.idelements.

I'm using Play for Java so no Scala examples please.

Thanks msl

Était-ce utile?

La solution

You said no scala but still it would be the easiest:

personList.map(_.id).mkString(",")

The templates are written in scala anyways, so I guess it won't do any harm to pick up some scala along the way.

If you're not happy with this solution, transform the personList in the controller and pass down the created String of ids.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top