调用名称中带有变量的变量-coldfusion? [英] Calling a variable with a variable in its name - coldfusion?

查看:16
本文介绍了调用名称中带有变量的变量-coldfusion?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用方括号表示法来引用动态变量.(如果您想了解应用程序,我正在遍历由查询创建的一组产品,为每个产品创建与其唯一 SKU 相关联的字段)

Attempting to use squarebracket notation to reference a dynamic variable. (I'm looping through a set of product created by a query, creating fields for each tied to their unique SKU, if you're wondering about application)

我已将其范围缩小到这段代码,当我尝试运行它时会引发无效表达式"错误.

I've narrowed it down to this chunk of code, which throws an "Invalid Expression" error when I try and run it.

<cfif FORM["QTY_" & SKU] NEQ ''>
    <div class="sopQty"><input type="number" min="0" name="QTY_#SKU#" value = "#FORM['QTY_' & SKU]#" /></div>
<cfelse>
    <div class="sopQty"><input type="number" name="QTY_#SKU#" /></div>
</cfif>

目标是传递上一页中的值(如果有),否则将该字段留空.我认为在这种情况下,我无法弄清楚语法的一些怪癖.下面的块中有错误:

The goal is to pass the value on from the previous page if there is one, else leave the field blank. I'm thinking there's some quirk of syntax in this case that I haven't been able to figure out. Error in block below:

类型:模板

消息:无效的表达式

标签:CFIF

定位线=62;列=17

Position Line=62; Column=17

详细错误表达式 [#FORM['QTY_' &SKU])#]

Detail Bad Expression [#FORM['QTY_' & SKU])#]

来源

60:                 <div class="sopSearch"><p>#SearchAlias#</p></div> 
61:                 <div class="sopPrice"><p>#ISBNupc#</p></div>
62:                  <cfif FORM["QTY_" & SKU] NEQ ''>
63:                     <div class="sopQty"><input type="number" min="0" name="QTY_#SKU#" value = "#FORM['QTY_' & SKU])#" /></div>
64:         <cfelse>

^ 来自底层 CFML 源代码的片段

^ Snippet from underlying CFML source

有什么建议吗?

推荐答案

这只是一个例子,因为我不知道你在哪里设置你的变量,但是在你的操作页面上尝试类似下面的操作:

This is just an example,because I do not know where you are setting your variables, but try something like the following on your action page:

<cfset SKU = "123">
<cfset dynamic_Var = "QTY_" & variables.SKU>
<cfif IsDefined("form[dynamic_Var]")>
  <cfoutput>#form[dynamic_Var]#</cfoutput>
<cfelse>
  fail
</cfif>

这是提交表格:

<form name="test" action="test.cfm">
    <input type="text" name="QTY_123" value="test">
    <input type="submit" name="submit" value="submit">
</form>

这篇关于调用名称中带有变量的变量-coldfusion?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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