我可以将结构传递给函数并将其转换为多个参数吗?

发布于 2024-12-25 12:33:14 字数 563 浏览 2 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫思念不要吵 2025-01-01 12:33:14

好的,我还没有对此进行测试,但我刚刚意识到我可以使用 来做到这一点。现在就尝试...

编辑:
这确实有效! 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文