gpt4 book ai didi

coldfusion - 使用|| OR 在 Coldfusion if 语句中使用 isDefined

转载 作者:行者123 更新时间:2023-12-02 20:23:57 26 4
gpt4 key购买 nike

我在 Coldfusion 2018 中使用 session 变量,并且我正在尝试弄清楚如何按照 if 语句的设置方式添加变量。

<cfif isDefined("session")
and structKeyExists(session, 'checkout')
and structKeyExists(session.checkout, 'info')
and structKeyExists(session.checkout.info, 'andor_1') >
<cfif session.checkout.info.andor_1 eq "And">
<strong>- All signatures are required.</strong>
</cfif>
</cfif>

or

<cfif isDefined("session")
and structKeyExists(session, 'checkout')
and structKeyExists(session.checkout, 'info')
and structKeyExists(session.checkout.info, 'bandor_1') >
<cfif session.checkout.info.bandor_1 eq "And">
<strong>- All signatures are required.</strong>
</cfif>
</cfif>

if 语句几乎相同 andor_1bandor_1,但其中任何一个可能并不总是存在,这就是我使用 isDefined 的原因。

我尝试过使用 ||or

 <cfif isDefined("session")
and structKeyExists(session, 'checkout')
and structKeyExists(session.checkout, 'info')
and structKeyExists(session.checkout.info, 'andor_1')
|| isDefined("session")
and structKeyExists(session, 'checkout')
and structKeyExists(session.checkout, 'info')
and structKeyExists(session.checkout.info, 'bandor_1')>
<cfif session.checkout.info.andor_1 eq "And" || session.checkout.info.bandor_1 eq "And">
<strong>- All signatures are required.</strong>
</cfif>
</cfif>

任何结合这些 cfif 的帮助将不胜感激。

最佳答案

CF 中的正确方法是“OR”,而不是 ||。

但是,在第一个示例中,您已将“OR”放在 IF 语句之外。试试这个:

 <cfif isDefined("session") AND structKeyExists(session, 'checkout') AND structKeyExists(session.checkout, 'info')
AND (
(structKeyExists(session.checkout.info, 'andor_1') AND session.checkout.info.andor_1 eq "And")
OR
(structKeyExists(session.checkout.info, 'bandor_1') AND session.checkout.info.bandor_1 eq "And")
)>

<strong>- All signatures are required.</strong>
</cfif>

关于coldfusion - 使用|| OR 在 Coldfusion if 语句中使用 isDefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53639288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com