使用JSTL forEach循环的varStatus作为ID [英] Use JSTL forEach loop's varStatus as an ID

查看:329
本文介绍了使用JSTL forEach循环的varStatus作为ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JSTL forEach循环中的计数,但我的代码似乎不起作用。

I want to use the count from the JSTL forEach loop, but my code doesnt seem to work.

<c:forEach items="${loopableObject}" var="theObject" varStatus="theCount">
    <div id="divIDNo${theCount}">
    </div>
</c:forEach>

产生

<div id="divIDNojavax.servlet.jsp.jstl.core.LoopTagSupport$1Status@5570e2" >


推荐答案

varStatus设置的变量是LoopTagStatus 对象,而不是int。使用:

The variable set by varStatus is a LoopTagStatus object, not an int. Use:

<div id="divIDNo${theCount.index}">

澄清:


  • $ {theCount.index} 从0开始计算

  • $ {theCount.count} 从1开始计算

  • ${theCount.index} starts counting at 0
  • ${theCount.count} starts counting at 1

这篇关于使用JSTL forEach循环的varStatus作为ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆