动态变量名ColdFusion [英] Dynamic Variable Names Coldfusion

查看:106
本文介绍了动态变量名ColdFusion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hey Guys,我有一个关于动态变量名的问题。发生了什么事是我有一个CFC构建表单的一部分,我使用表中的一些数据。然后cfc将表单的代码作为字符串发送回页面。我需要为这些表单字段赋值,以便人们不要覆盖数据。我拉在cfc中的函数中的数据。所以我试图把这个动态变量放入字符串,它是搞乱了我的事情。我不断收到一个错误,说

Hey Guys, I'm having a tad of an issue dealing with Dynamic Variable Names. What is happening is I have a CFC that builds part of form for me using some data in a table. Then the cfc sends the form's code back to the page as a string. Well I need to assign values to these form fields so people don't overwrite the data. I'm pulling the data in the function in the cfc. So I'm trying to throw this dynamic variable into the string and it is messing things up for me. I keep getting an error saying

CFML变量名不能以。结尾。字符。

这里是我使用的代码给我的错误。我不是所有太有经验的编程我没有做这个太长时间。所以任何输入将是真棒。

Here is the code I'm using that gives me the error. I'm not all too experienced with programming I haven't been doing this too long. So ANY input would be awesome.

<!--- ================================================================== --->



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

无论如何,如果你能给我任何输入或建议,非常感谢。

So anyway if you can give me any input or advice that would be great. Thanks a lot.

代码就在这里。

                    <cfset returnVar = returnVar & #arguments.catFormQuery.catName# & ":&nbsp;&nbsp;<input type='text' name='#catNameNoSpace#' value=" & getListingInformation.#catNameNoSpace# & "><br />">


推荐答案

这肯定不行, :

getListingInformation.#catNameNoSpace#

评估是魔鬼,但你可以使用数组风格的语法。唯一的警告是,你需要明确指定要从中获取值的行(如果查询没有行,则会出错)。

Evaluate is the devil, but you can use the array-style syntax instead. The only caveat is that you need to explicitly specify the row from which you want the value to come (and if the query has no rows, this will error out).

getListingInformation[catNameNoSpace][1]

这篇关于动态变量名ColdFusion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆