评估 JSTL 中的 list.contains 字符串 [英] Evaluate list.contains string in JSTL
本文介绍了评估 JSTL 中的 list.contains 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果 JSP 中存在某些值,我需要隐藏一个元素
I need to hide an element if certain values are present in the JSP
这些值存储在一个列表中,所以我尝试了:
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屋!
查看全文