执行ajax组件http://path/to/my/component.cfc?method=something没有执行该方法

发布于 2024-07-30 07:20:00 字数 1292 浏览 4 评论 0原文

我有一个具有远程功能的 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>

您能告诉我这里缺少什么吗?

谢谢!

I have a CFC with a remote function and am trying to populate it into my cfm page's cfselect element. But I am not getting anything in the select.

I tried executing the cfc directly, but the method that I call does not execute.

Here is the code for the 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>

Here is the code for the 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>

Could you please tell me what am I missing here?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2024-08-06 07:20:00

所以下面的代码对我有用。 我改变了一些东西,很难知道它做了什么,但是:

  1. 变量范围为变量
  2. 删除了一些复杂性
  3. 将查询列从整数更改为 varchar

-

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

So the following code works for me. I changed a few things, so hard to know what did it but:

  1. Var-scoped the variables
  2. Removed some complexity
  3. Changed the query column from integer to varchar

-

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文