是否可以用参数动态填充 CFC?
以下代码错误:
<cfdbinfo datasource="#Application.DSN#" name="getCols" type="columns" table="#this.tableName#">
<cftry>
<cfquery name="getColumnDetails" dbtype="query">
SELECT COLUMN_NAME,TYPE_NAME
FROM getCols
WHERE IS_PRIMARYKEY = 'NO'
</cfquery>
<cfcatch>
<cfset this.ErrorState = true>
<cfthrow message="General DB Error">
</cfcatch>
</cftry>
<cfloop query="getColumnDetails">
<cfargument name="#getColumnDetails.COLUMN_NAME#" displayName="values" type="Any" required="false" />
</cfloop>
但我真的很想知道是否可以动态设置 CFC 的参数 - 或者简单地传入一个结构并处理它是否更好?
谢谢
抢
The following code errors:
<cfdbinfo datasource="#Application.DSN#" name="getCols" type="columns" table="#this.tableName#">
<cftry>
<cfquery name="getColumnDetails" dbtype="query">
SELECT COLUMN_NAME,TYPE_NAME
FROM getCols
WHERE IS_PRIMARYKEY = 'NO'
</cfquery>
<cfcatch>
<cfset this.ErrorState = true>
<cfthrow message="General DB Error">
</cfcatch>
</cftry>
<cfloop query="getColumnDetails">
<cfargument name="#getColumnDetails.COLUMN_NAME#" displayName="values" type="Any" required="false" />
</cfloop>
but I would really like to know if it is possible to dynamically set the arguments for a CFC — or is it better to simply pass in a struct and deal with that?
Thanks
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不太可能。
正如您所说,有两种方法,不要定义 cfargument 标记,而是查找通过 StructKeyExists(ARGUMENTS, aDynamicName) 传入的它们,或者创建一个代码生成器并将这些方法写入文件。
Unlikely.
Two ways, as you said, don't define the cfargument tags and instead look for them being passed in with StructKeyExists(ARGUMENTS, aDynamicName) or, create a code generator and write these methods to a file.
我尝试做与您正在做的事情类似的事情的一种方法是沿着以下路线进行操作:
然后循环潜在列的列表,使用列表中的每个元素作为要在 columnValues 结构中搜索的索引。 如果该值存在于结构中,那么你就很好; 否则,您将忽略更新中的该列。
然后,您可以像这样调用该函数:
要交替获取您要查找的列
,您可以忽略 PotentialColumns 参数,而只需在 cfc 中获取该信息:
One way I've tried to do similar things to what you're doing is something along these lines:
and then loop over the list of potential columns, using each element in the list as the index to search for in the columnValues struct. if that value exists in the struct, then yo'ure good; otherwise, you ignore that column in the update.
you'd then call the function something like this:
to get the columns you're looking for
alternately, you could ignore the potentialColumns argument and just get that information in your cfc: