我从操作中获取了一个列表,该列表要与GSP中的另一个值进行比较。我希望能够查看该值是否在返回的列表中。我知道你可以直接比较
<g:if a="a">
但是我正在寻找的是数组比较中的字符串
<g:if a in [a,b,c,d]>
需要类似的东西
<g:if test="${myList}.contains(${username})}">
尝试过:
<g:if test="${myList.contains(username)}">
一切都返回false(即使包含应该为true)
测试数据:
${myList.keySet()}
${username}
<g:if test="${failedToSync.keySet().contains(username)}">
<li>${username} yes</li>
</g:if>
<g:else>
<li>${username} no</li>
</g:else>
输出:
[a] b
b no
[a] a
a no
附加信息:
"${username.stripIndent() == failedToSync.keySet()[0]}"
返回true<g:if test="${(failedToSync.keySet()).contains(username.stripIndent())}"> returns false
最佳答案
在Groovy中,您可以在任何集合上使用.contains
。所以,对于你的情况
<g:if test="${['a', 'b', 'c'].contains('a')}">
...
</g:if>
关于list - grails如何检查值是否在gsp的列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24495782/