Coldfusion:如何从函数循环查询

Jac*_*sky 1 coldfusion coldfusion-9

我有一个多次调用的查询,具体取决于变量vchrStatus

<cffunction name="getGalleriesByStatus" output="no" returntype="query">
    <cfargument name="vchrStatus" type="string" required="yes">
    <cfquery 
        name="getGalleries"
        datasource="#Application.dsn#">
        /// Long complicated query in here
    </cfquery>
    <cfset var result="#getGalleries#">
    <!--- Return it --->
    <cfreturn result>
</cffunction>
Run Code Online (Sandbox Code Playgroud)

我用cfdump测试了这个函数,并输出了所需的结果.

现在我想在cfoutput中循环结果

<cfoutput query="getGalleriesByStatus('Pending')">
Run Code Online (Sandbox Code Playgroud)

但是我收到错误:属性查询的值(当前为getGalleriesByStatus('Pending'))无效.

Ada*_*ron 10

<cfoutput>获取查询变量的名称(即:字符串).它不会采用评估查询的表达式.所以你需要这个:

<cfset someVar = getGalleriesByStatus('Pending')>
<cfoutput query="someVar">
Run Code Online (Sandbox Code Playgroud)

这是违反直觉的,但情况确实如此.它也不在文件中,即sux.