我想轻松地将参数的结构内容放入组件所有功能的变量范围内。'Title' 是 searchitems 结构之一。
<cffunction name="setSearch" acces="public" returntype="void">
<cfargument name="searchitems" type="struct" required="true" />
<cfset variables = arguments.searchitems>
<cfset variables.test = "yo">
</cffunction>
<cffunction name="testit" acces="public" returntype="void">
<cfdump var="#variables.test#"><br>
<cfif isdefined('variables.test')>found in variables.test </cfif>
<cfif isdefined('variables.variables.test')>found in variables.variables.test </cfif>
<hr>
<cfdump var="#variables.title#"><br>
<cfif structkeyexists(variables,'title')>found in variables.title with structkeyexists </cfif>
<cfif structkeyexists(variables.variables,'title')>found in variables.variables.title with structkeyexists</cfif>
<cfif isdefined('variables.title')>found in variables.title </cfif>
<cfif isdefined('variables.variables.title')>found in variables.variables.title</cfif>
</cffunction>
但是运行它会给出:
yo
found in variables.test
mytitletext
found in variables.variables.title with structkeyexists
found in variables.variables.title
我觉得很奇怪,标题可以作为 variables.title 转储或输出,但不能用 isDefined 或 structkeyexists 检测到。有没有更有效的分配方式
<cfset variables = arguments.searchitems>