我是新版ColdFusion的新手,在使用cfselect的简单数据绑定时遇到了一些问题。我已经尽了最大的努力来彻底研究它,我甚至回到了一本教科书上,基本上在测试文件中复制了代码示例,但我仍然得到相同的错误。
我正在尝试构建一种常见的情况,即有两个cfselect,第二个依赖于第一个,但在这一点上,我甚至不能让第一个cfselect工作。返回的错误为:
“绑定选择框Species_id失败,绑定值不是2D数组或有效的序列化查询”
提前感谢您的帮助。代码如下:
<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>发布于 2013-04-12 03:09:54
看起来你的绑定语法是关闭的。绑定表达式应以绑定的type: (cfc、url、javascript)开头。由于您要绑定到组件,因此必须在其前面加上"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>然后在选择列表中指定display和value属性。
<cfselect name="service"
bind="cfc:office.cfc:data.getSpecies()"
display="Species"
value="Species_id" ...>https://stackoverflow.com/questions/15955121
复制相似问题