Coldfusion 如果语句有效或条件无效?

Coldfusion 如果语句有效或条件无效?,coldfusion,Coldfusion,If语句不起作用,仍然显示 ,只有当我有一个条件时才有效 <cfif #GetCurrentUserDept.dept_id# neq 29 || #GetCurrentUserDept.dept_id# neq 40 > code .... </cfif> 代码。。。。 考虑按如下方式编写您的if语句: <cfif NOT (GetCurrentUserDept.dept_id eq 29 OR GetCurrentUserDep

If语句不起作用,仍然显示 ,只有当我有一个条件时才有效

 <cfif #GetCurrentUserDept.dept_id# neq 29 || #GetCurrentUserDept.dept_id# neq 40 >      
        code ....
</cfif>

代码。。。。

考虑按如下方式编写您的if语句:

<cfif NOT (GetCurrentUserDept.dept_id eq 29 OR GetCurrentUserDept.dept_id eq 40) >      
        code ....
</cfif>

代码。。。。
目前,您的代码相当于:

<cfif NOT (GetCurrentUserDept.dept_id eq 29 AND GetCurrentUserDept.dept_id eq 40) >      
        code ....
</cfif>

代码。。。。

我们知道
GetCurrentUserDept.dept\u id
不能同时等于40和29。这就是它无法工作的原因。

如果
getCurrentUserDept.deptID
为29或40,则代码将不会显示

<cfif NOT listFind('29,40', getCurrentUserDept.deptID)>
  code...
</cfif>

代码。。。

运行此代码时,部门id的值是多少?@danbracuk现在是40您的逻辑是什么?您希望在什么条件下执行
code
?如果我只将其保留为40,它将工作,并且不显示code,但29不等于40。这让你进退两难。您可以将or更改为and,或者按照Matt的建议进行操作。这取决于您的需求,随着我们的讨论,您的需求变得越来越不清晰。是否要解释此建议的基本原理?如果
dept\u id
不是
29或40,则代码将执行。这有帮助吗?有更简单的方式来表达这个或那个。马特的回答就是其中之一。