2013-04-11 20 views
2

我是新來的ColdFusion的新版本,我有一個簡單的數據綁定到cfselect的問題。我已經盡力徹底研究它,並且我甚至回到了教科書,基本上重複了測試文件中的代碼示例,但仍然得到相同的錯誤。cfselect不綁定到cfc

我試圖建立有2個cfselects和第二個依賴於第一,但在這一點上,我甚至無法得到第一個工作的共同情況。返回的錯誤是:

「綁定失敗的選擇框Species_id,綁定值不是一個二維數組或有效的序列化查詢」

預先感謝任何幫助。以下是代碼:

<cfcomponent> 
    <cffunction name="getSpecies" access="remote" returnType="array"> 
    <cfset var rsData = ""> 
    <cfset var myReturn=ArrayNew(2)> 
    <cfset var i=0> 
     <cfstoredproc datasource="#application.dsn#" procedure="up_get_Species"> 
      <cfprocresult name="DataResults"> 
     </cfstoredproc> 
    <cfloop query="DataResults"> 
     <cfset myReturn[rsData.currentRow][1]=rsData.Species_id> 
     <cfset myReturn[rsData.currentRow][2]=rsData.Species> 
    </cfloop> 
    <cfreturn myReturn> 
    </cffunction> 
</cfcomponent> 

<html> 
<head> 
    <title>CFSelect Example</title> 
</head> 
<body> 
<h1>Sandbox for getting cfselect bind working</h1> 
<cfform name="form1"> 
Wood Type 
<br> 
<cfselect name="Species_id" bind="office.cfc:data.getspecies()" 
    bindOnLoad = "true" /> 
</cfform> 
</body> 
</html> 
+0

幾點。首先你應該在你的cfc中設置DataResults變量。其次,如果您還沒有這樣做,請確保您的cfc方法在您嘗試將其用於綁定之前通過從Coldfusion中調用它來返回預期結果。它使故障排除更容易。 – 2013-04-11 21:55:41

回答

2

看起來您的綁定語法已關閉。綁定表達式應該以綁定(cfc,url,javascript)的type:開頭。既然你綁定到一個組件,您必須"cfc:"前言它,即

 bind="cfc:path.to.yourComponentName.yourFunctionName()" 

這就是說,以後CF的版本都支持綁定到查詢,從而簡化結合。只需將功能returnType更改爲query即可。

<cffunction name="getSpecies" access="remote" returnType="query"> 
    <!--- Be sure to Local scope all variables, including query names ---> 
    <cfstoredproc datasource="#application.dsn#" procedure="up_get_Species"> 
      <cfprocresult name="Local.DataResults"> 
    </cfstoredproc> 

    <cfreturn Local.DataResults > 
</cffunction> 

然後指定你的選擇列表中的displayvalue屬性。

<cfselect name="service" 
      bind="cfc:office.cfc:data.getSpecies()" 
      display="Species" 
      value="Species_id" ...>