【问题标题】:JSTL Conditional Operator with variable带变量的 JSTL 条件运算符
【发布时间】:2013-12-10 09:20:17
【问题描述】:

在处理 jstl 标签时,我遇到了 foreach 循环:

<c:forEach items="#{data.steps}" var="item" varStatus="status">
        <li><a href="" class="${status.index == '1'? 'current' : ''}">#{item}</a></li>          
    </c:forEach>  

如何用变量替换静态“1”(status.index == '1')?应该看起来像:status.index == '1' == #{data.step}?

【问题讨论】:

    标签: foreach jstl


    【解决方案1】:

    假设您想用页面/请求/会话/应用程序范围中存在的变量名称“步骤”替换常量“1”。代码如下:

    <a href="" class='${status.index == step ? "current" : ""}'>
    

    如果 step 是 bean 'beanA' 现有页面/请求/会话/应用程序范围范围的属性。你可以这样编码

    <a href="" class='${status.index == beanA.step ? "current" : ""}'>
    
    // beanA has a method getStep().
    

    【讨论】:

      猜你喜欢
      • 2014-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 2012-03-09
      相关资源
      最近更新 更多