1
<cfparam name="airInfo.leaving"     type="struct" default="#structNew()#">
<cfparam name="flightInfo.depart"   type="string" default="departing">
<cfparam name="flightInfo.arrive"   type="string" default="arriving">

<cfset flightInfo   = airInfo.leaving>
<cfset fromInfo     = flightInfo.depart>
<cfset arriveInfo   = flightInfo.arrive>

<cfdump var="#flightInfo#">

This should work... I think, but I keep getting an error saying depart is undefined in flightInfo. I know I could use if structKeyExists() but this is just a snippet of a larger application. I can't be checking all the variables in that mannor, and really need to use cfparam. What am I missing from this?

4

1 回答 1

4

也许第二个和第三个 cfparams 应该设置 airInfo.depart 和 airInfo.arrive 而不是 flighInfo.depart 和 flightInfo.arrive。

编辑:我应该提到您的 flightInfo 变量被您在第一个 cfparam 中创建的空结构覆盖,这就是您收到未定义错误的原因。

如果您的意图是使用离开和到达的默认航班信息,您应该在 airInfo.leaving 中设置这些变量,就像在 airInfo.leaving.depart 和 airInfo.leaving.arrive 中一样,然后将 airInfo.leaving 分配给 flightInfo。

于 2012-07-02T15:39:37.413 回答