velocity-字母序号 list

时间:2021-08-22 19:12:18

版权声明:本文为博主原创文章,未经博主允许不得转载。

【需求】

遍历一个list,同时需要在每个item前面显示字母序号,例如A,B,C,D

【代码】

  1. #set($zimu = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"])
  2. #set($k=0)
  3. #foreach($item in ${questionDTO.answerList})
  4. <span class="exe_mc_option" data-obid="${item.obid}">
  5. <span class="optionid">$zimu.get($k)</span>${item.answerContext}
  6. </span>
  7. #set($k=$k+1)
  8. #end

【说明】
这里定义了一个k,如果使用$zimu.get($velocityCount-1)这种形式会报错,没有深究原因。