在JSTL中评估list.contains字符串 [英] Evaluate list.contains string in JSTL

查看:124
本文介绍了在JSTL中评估list.contains字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果JSP中存在某些值,我需要隐藏元素

I need to hide an element if certain values are present in the JSP

值存储在List中,所以我尝试了:

The values are stored in a List so I tried:

<c:if test="${  mylist.contains( myValue ) }">style='display:none;'</c:if>

但是,它不起作用。

如何评估列表是否包含JSTL中的值,列表和值是字符串。

How can I evaluate if a list contains a value in JSTL, the list and the values are strings.

推荐答案

可悲的是,我认为JSTL不支持任何东西,只是迭代所有元素来解决这个问题。在过去,我在核心标记库中使用了forEach方法:

Sadly, I think that JSTL doesn't support anything but an iteration through all elements to figure this out. In the past, I've used the forEach method in the core tag library:

<c:set var="contains" value="false" />
<c:forEach var="item" items="${myList}">
  <c:if test="${item eq myValue}">
    <c:set var="contains" value="true" />
  </c:if>
</c:forEach>

此运行后,如果myList包含myValue,则$ {contains}将等于true。

After this runs, ${contains} will be equal to "true" if myList contained myValue.

这篇关于在JSTL中评估list.contains字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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