【发布时间】:2019-08-16 15:11:42
【问题描述】:
如何确定列表或地图是否包含特定字符串?例如(伪代码):
<#if listofItems.contains("random-string") >
the map contains a key called random-string
</#if>
【问题讨论】:
标签: freemarker
如何确定列表或地图是否包含特定字符串?例如(伪代码):
<#if listofItems.contains("random-string") >
the map contains a key called random-string
</#if>
【问题讨论】:
标签: freemarker
如果是列表:
<#if listOfItems?seq_contains("random-string")>
...
</#if>
如果是地图:
<#if someMap["random-string"]??>
...
</#if>
如果是地图且键不包含特殊字符:
<#if someMap.randomString??>
...
</#if>
如果它是一个映射并且你正在寻找一个键值对的值:
<#if someMap?values?seq_contains("random-string")>
...
</#if>
【讨论】:
我认为这种方法应该可行
<#if listofItems['random-string']?? >
you are inside if block
</#if>
【讨论】: