需要在scala.html中使用计数器变量,并使用@for(i

问题描述 投票:0回答:1
play-framework-twirl-template

1. I have multiple questions in variable list. 2. Need to declare variable outside for loop and use as counter variable in for loop. like @var count=0; 2. I iterate list on scala.html file @for(d <-list){ count++ or count+=1;// getting error } 3. through this loop need to print number with questions like Sr.No QuestionName Option.. 1 ABC A.. 2 ZYX D..

playframework
1个回答
0
投票

您应该在scala集合上使用zipWithIndex功能(scala文档中的更多信息:here

大量使用:

@for((value, index) <- list.zipWithIndex){

  @* Print value *@
  @value 

  @* Print index - first index will be 0 *@
  @index

  @* Print index + 1 *@
  @{index+1}

}



© www.soinside.com 2019 - 2024. All rights reserved.