我可以将结构传递给函数并将其转换为多个参数吗?
在 ColdFusion 中,有什么方法可以将参数结构传递给具有多个可选参数的函数吗?
例如,我想做这样的事情:
<cfset myResults = myFunction(myStruct) />
<cffunction name="myFunction" ... >
<cfargument name="myArg1" type="numeric" required="no" default="" />
<cfargument name="myArg2" type="string" required="no" default="" />
<cfargument name="myArg3" type="numeric" required="no" default="" />
.....
</cffunction>
其中“myStruct”具有键值对的随机组合 - 例如“myArg3”:222和“myArg2”:“hello”。
这是可能的,还是我必须专门列出每个参数(对每个参数检查“isDefined”)?
In ColdFusion, is there any way to pass in a struct of parameters to a function with multiple optional parameters?
For example, I want to do something like this:
<cfset myResults = myFunction(myStruct) />
<cffunction name="myFunction" ... >
<cfargument name="myArg1" type="numeric" required="no" default="" />
<cfargument name="myArg2" type="string" required="no" default="" />
<cfargument name="myArg3" type="numeric" required="no" default="" />
.....
</cffunction>
Where "myStruct" has a random combination of key-value pairs - for example, "myArg3":222 and "myArg2":"hello".
Is this possible, or do I have to specifically list each argument (with a check of "isDefined" for each one)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我还没有对此进行测试,但我刚刚意识到我可以使用
来做到这一点。现在就尝试...编辑:
这确实有效! Sergii 对我的原始语法(不使用 cfinvoke)的建议也有效。
Ok, I haven't tested this yet, but I just realized I might be able to do this using a
<cfinvoke argumentCollection="#myStruct#">
. Will try that now...Edit:
This did work! And Sergii's suggestion for my original syntax without a cfinvoke works as well.