动态变量名称 Coldfusion

发布于 2024-08-10 11:35:35 字数 2100 浏览 5 评论 0原文

大家好,我在处理动态变量名称时遇到了一些问题。发生的情况是我有一个 CFC,它使用表中的一些数据为我构建部分表单。然后 cfc 将表单的代码作为字符串发送回页面。好吧,我需要为这些表单字段分配值,这样人们就不会覆盖数据。我正在提取 cfc 中函数中的数据。所以我试图将这个动态变量放入字符串中,这让我把事情搞乱了。我不断收到错误消息

CFML 变量名称不能以“.”结尾

这是我正在使用的代码,它给了我错误。我对编程不太有经验,我从事这行的时间不长。所以任何输入都会很棒。

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

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

所以无论如何,如果您能给我任何意见或建议,那就太好了。多谢。

代码就在底部。

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

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

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

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# & ":  <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.

The code is right down here at the bottom.

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

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

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

发布评论

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

评论(4

心的位置 2024-08-17 11:35:35

这绝对行不通,它不是有效的 CFML:

getListingInformation.#catNameNoSpace#

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

getListingInformation[catNameNoSpace][1]

This definitely won't work, it's not valid CFML:

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]
软甜啾 2024-08-17 11:35:35

Sixten 的答案有一个可以使用的语法,但您仍然需要注意变量名称中的非法字符,如其他地方所回答的那样。变量的终极指南在这里:http://www. depressedpress.com/Content/Development/ColdFusion/Articles/Variables/Index.cfm,尤其是本节http://www.depressedpress.com/Content/Development/ColdFusion/Articles/Variables/NotationIndexed.cfm

Sixten's answer has a syntax you can use, but you'll still need to watch out for illegal characters in variable names as answered elsewhere. The ultimate guide for variables is here: http://www.depressedpress.com/Content/Development/ColdFusion/Articles/Variables/Index.cfm, especially this section http://www.depressedpress.com/Content/Development/ColdFusion/Articles/Variables/NotationIndexed.cfm

我喜欢麦丽素 2024-08-17 11:35:35

略有不同,但可能对任何查看此内容的人有用:您还可以使用 Variables["staticPartOfVariableName#DynamicPartOfVariableName#"] 。

Slightly different but might be useful to anyone looking at this: You can also use Variables["staticPartOfVariableName#DynamicPartOfVariableName#"] .

若水般的淡然安静女子 2024-08-17 11:35:35

好吧,我想我明白了。但我真的不喜欢我必须这样做的方式。

evaluate("getListingInformation.#catNameNoSpace#")

我之前听说过使用评估很慢而且不是很干净。有更好的选择吗?

Alright I think I figured it out. I don't really like how I had to do it though.

evaluate("getListingInformation.#catNameNoSpace#")

I've heard somewhere before that using evaluate is slow and not very clean. Is there a better option?

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