具有多个值的一个变量的IF语句

问题描述 投票:1回答:2

是否有更好的方法来编写此IF语句来测试变量的多个选项?

<#if PRINTER_PET.RETAILER_NAME = 'BEST BUY' || PRINTER_PET.RETAILER_NAME = 'Best Buy Purchasing LLC'>
document 1 
<#elseif  PRINTER_PET.RETAILER_NAME = 'AMAZON' || PRINTER_PET.RETAILER_NAME = 'Amazon Fulfillment Services Inc Attn: Amazon.com' >
document 2
</#if>

谢谢Erica

freemarker multiple-value responsys
2个回答
2
投票

你可以将PRINTER_PET.RETAILER_NAME提取到一个变量中,比如<#assign retName = PRINTER_PET.RETAILER_NAME>,然后它会更短(<#if retName == 'foo' || retName == 'bar'>等)。另外,如果你有很多字符串要比较,<#if ['foo', 'bar', 'baaz']?seq_contains(retName)>可能会更好。


1
投票

关注Freemrker Comparison示例并使用=="

<#if PRINTER_PET.RETAILER_NAME == "BEST BUY" || PRINTER_PET.RETAILER_NAME == "Best Buy Purchasing LLC">
document 1 
<#elseif  PRINTER_PET.RETAILER_NAME == "AMAZON" || PRINTER_PET.RETAILER_NAME == "Amazon Fulfillment Services Inc Attn: Amazon.com" >
document 2
</#if>

user == "Big Joe"中的<#if ...>表达式将评估为布尔值true,因此上面将说“它是大乔”。

逻辑或:||

© www.soinside.com 2019 - 2024. All rights reserved.