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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top