2013-04-11 24 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" ...>