开发者

Ternary operator blowing up

I would like some help with my syntax for the following ternary operator (which keeps blowing) in Coldfusion:

iif(structKeyExists(session, "newUser") ? session.newUser.planId : 0)

It's part of the following model call:

user = model("user").new(UUID=createUUID(), planId=iif(structKeyExists(session, "newUser") ? session.newUser.planId : 0));

It keeps blowing up, however:

Parameter validation error for the IIF function. The funct开发者_开发百科ion takes 3 parameter.


According to Adobe's documentation, the function syntax for iif looks like this:

IIf(condition, string_expression1, string_expression2)

So in your case, you would call it like this:

iif(structKeyExists(session, "newUser"), session.newUser.planId, 0)

This is different from the ternary operator (?:), which is described here and follows the following syntax:

(Boolean expression)? expression1 : expresson2

Which, in your case, would look like this:

planId=structKeyExists(session, "newUser") ? session.newUser.planId : 0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜