CFC向cfselect返回多个查询

时间:2011-06-08 19:43:47

标签: coldfusion coldfusion-8 cfc

我有一个返回多个查询的cffunction。我正在使用'struct'作为我的返回类型。我的问题是,如何在多个cfselects中使用函数返回。我可以让cfdump工作,但不知道要放入什么

cfc
 <cffunction name="cfcName" access="remote" returntype="struct">
  <cfset var myStruct=StructNew()>

  <!---Query1---->
  <cfquery name="Query1" datasource="dsn">
   SELECT DISTINCT Col1
   FROM Table1
   ORDER BY Col1 
  </cfquery>

  <!---Query2---->
  <cfquery name="Query2" datasource="dsn">
   SELECT DISTINCT Col2
   FROM table2
   ORDER BY Col2 
  </cfquery>

  <cfset myStruct.Query1= Query1>
  <cfset myStruct.Query2= Query2>

  <cfreturn myStruct>
</cffunction>

<cfinvoke
  component="CMPT"
  method="cfcName"
  returnvariable="Return_cfcName">
</cfinvoke>


cfm,
(Query 1 returns should diplay in this cfselect)
<cfselect name="Select1" required="no" query="?" value="?" display="?" queryPosition="below">
        <option value="">ALL</option>
</cfselect>

(Query 2 returns should diplay in this cfselect)
<cfselect name="Select2" required="no" query="?" value="?" display="?" queryPosition="below">
        <option value="">ALL</option>
</cfselect>

提前感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

这应该可以解决问题......

<cfselect name="Select1" required="no" query="Return_cfcName.Query1" value="Col1" display="Col1" queryPosition="below">
        <option value="">ALL</option>
</cfselect>


<cfselect name="Select2" required="no" query="Return_cfcName.Query2" value="Col2" display="Col2" queryPosition="below">
        <option value="">ALL</option>
</cfselect>