动态变量命名Coldfusion

NCX*_*001 2 variables coldfusion cfc dynamic

嘿伙计们,我有一个处理动态变量名称的问题.发生的事情是我有一个CFC,它使用表中的一些数据为我构建表单的一部分.然后cfc将表单的代码作为字符串发送回页面.我需要为这些表单字段赋值,以便人们不会覆盖数据.我在cfc中的函数中提取数据.所以我试图将这个动态变量抛入字符串中,这对我来说很糟糕.我一直在说错误

A CFML variable name cannot end with a "." character.

这是我正在使用的代码,它给了我错误.我对编程没有太多经验我没有这么做太久.所以任何输入都会很棒.

<!--- ================================================================== --->
Run Code Online (Sandbox Code Playgroud)

            <cfargument name="catFormQuery" type="query" required="yes">
            <cfargument name="listingID" required="yes">

            <cfset var getListingInformation = "">
            <cfset var returnVar = "">
            <cfset var fieldValue = "">
            <cfset var catNameNoSpace = "">

            <!--- get the listing Information --->
            <cfquery name="getListingInformation" datasource="backEndDSN">
             Select * from listings
                where listingID = #arguments.listingID#
            </cfquery>

<cfoutput query="arguments.catFormQuery">
             <!---====================--->
                <!--- Set catNameNoSpace --->
             <!---====================--->

                <cfset catNameNoSpace = replaceNoCase(arguments.catFormQuery.catName, " ", "_")>

 <!---==========--->
 <!--- for text --->
                <!---==========--->
                <cfif arguments.catFormQuery.catType eq 'text'>
                    <cfset returnVar = returnVar & #arguments.catFormQuery.catName# & ":&nbsp;&nbsp;<input type='text' name='#catNameNoSpace#' value=" & getListingInformation.#catNameNoSpace# & "><br />">
                </cfif>
Run Code Online (Sandbox Code Playgroud)

所以,无论如何,如果你能给我任何意义重大的意见或建议.非常感谢.

代码就在底部.

                    <cfset returnVar = returnVar & #arguments.catFormQuery.catName# & ":&nbsp;&nbsp;<input type='text' name='#catNameNoSpace#' value=" & getListingInformation.#catNameNoSpace# & "><br />">
Run Code Online (Sandbox Code Playgroud)

Six*_*tto 13

这肯定是行不通的,它不是有效的CFML:

getListingInformation.#catNameNoSpace#
Run Code Online (Sandbox Code Playgroud)

Evaluate是魔鬼,但您可以使用数组样式语法.唯一需要注意的是,您需要显式指定要从中获取值的行(如果查询没有行,则会出错).

getListingInformation[catNameNoSpace][1]
Run Code Online (Sandbox Code Playgroud)