binding - cfselect 未绑定(bind)到 cfc

标签 binding coldfusion coldfusion-10 cfselect

我是较新版本的 ColdFusion 的新手,并且在将简单数据绑定(bind)到 cfselect 时遇到问题。我已经尽力彻底研究它,甚至回到了教科书,基本上在测试文件中复制了代码示例,但我仍然遇到相同的错误。

我正在尝试构建一种常见情况,其中有 2 个 cfselect,而第二个依赖于第一个,但此时,我什至无法让第一个工作。返回的错误是:

“选择框 Species_id 绑定(bind)失败,绑定(bind)值不是二维数组或有效的序列化查询”

预先感谢您的帮助。这是代码:

<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>

最佳答案

您的绑定(bind)语法似乎已关闭。绑定(bind)表达式应以绑定(bind)的type: 开头(cfc、url、javascript)。由于您要绑定(bind)到组件,因此必须在其前面加上 "cfc:",即

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

也就是说,CF 的更高版本支持绑定(bind)到查询,这简化了绑定(bind)。只需将函数 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" ...>

关于binding - cfselect 未绑定(bind)到 cfc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15955121/

相关文章:

具有深/浅绑定(bind)的动态/静态范围(练习)

Jquery 使用 Coldfusion 自动完成

coldfusion - 使用 ColdFusion 上传文件,文件过大超时?

.net - 将 IEnumerable 变量从 ColdFusion 传递到 .NET

iis-7 - IIS7 正在丢失 cffileupload (CF10) 的经过身份验证的用户

coldfusion - 如何将 Coldfusion10 查询的结果导出为 html?

c# - WP8 : LongListMultiSelector Tap Item Trigger MVVM

c# - 单选按钮绑定(bind) MVVM 应用程序

javascript - 需要一个在三个值之间循环的切换按钮

javascript - 访问组件 Controller 中的绑定(bind)变量