我有一个带远程功能的CFC,我试图将它填充到我的cfm页面的cfselect元素中。但我在选择中没有得到任何东西。
我尝试直接执行cfc,但是我调用的方法没有执行。
以下是CFC的代码:
<cfcomponent output="false">
<cffunction name="getYear" access="remote" returnType="query">
<cfset yearlist = QueryNew("yr","integer")>
<cfset temp = QueryAddRow(yearlist,3)>
<cfset counter = 1>
<cfloop from="#evaluate(year(Now())-1)#" to="#evaluate(year(Now())+1)#" index="y">
<cfset temp = QuerySetCell(yearlist,"yr",y,counter)>
<cfset counter = counter + 1>
</cfloop>
<cfreturn yearlist>
</cffunction>
</cfcomponent>
以下是CFM的代码
<body>
<cfform>
<table>
<tr>
<td>Select Year:</td>
<td><cfselect name="yearval"
bind="cfc:cfc.ajaxcomp.getYear()"
value="yr"
display="yr"
bindonload="true" /></td>
</tr>
</table>
</cfform>
</body>
你能告诉我在这里缺少什么吗?
谢谢!
答案 0 :(得分:1)
所以以下代码适合我。我改变了一些东西,很难知道它做了什么但是:
-
<cfcomponent output="false">
<cffunction name="getYear" access="remote" returnType="query">
<cfset var y = 0 />
<cfset var yearList = QueryNew("yr","varchar")>
<cfloop from="#year(Now())-1#" to="#year(Now())+1#" index="y">
<cfset queryAddRow(yearList) />
<cfset QuerySetCell(yearList,"yr",y)>
</cfloop>
<cfreturn yearlist>
</cffunction>
</cfcomponent>