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

标签 coldfusion coldfusion-2018

我在 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/

相关文章:

t-sql - 从 cfquery 中删除事务

coldfusion - 尽管“启用空支持”已关闭,但在 cf2018 中启用了空

javascript - 将正则表达式从 JavaScript 翻译成 ColdFusion?

mysql - 不止一个 WHERE 条件导致错误 : You have an error in your SQL syntax;

arrays - 从数据可能不存在的数组中获取元素

coldfusion - 从 Coldfusion 11 升级到 Coldfusion 2018 后,cfgrid 不起作用

docker - 如何在 Docker 中挂载 ColdFusion 卷?

javascript - 使用 url 通过 javascript 访问 CGI

pdf - 如何在 ColdFusion 的封面中添加批准的图章

coldfusion - 在参数名称中使用连字符