我无法引用动态变量

时间:2016-03-22 19:32:11

标签: loops variables dynamic coldfusion reference

尝试使用动态表单字段名称。我可以在页面上获取它们但我不能引用它们来插入或从表中选择。之前我已经用数字动态命名表单字段,然后循环遍历它们以将数据插入到表中,但这些项目将被插入到不同的表中,所以我想通过名称引用它们,我尝试了几个选项和我到目前为止所做的一切都收到了错误。 我在表单上有4到6个字段,每个部分都有一个“添加”按钮。我想点击添加按钮并将字段插入到特定的表格中,每个部分下面都有一个表格,然后会显示刚刚添加的数据。

<cfif structKeyExists(form,"Add")>
    <cfquery name = "getTableColumnHeadings">
        SELECT * FROM '#enclTable#'  <<< errors here  >>>  enclTable is undefined
    </cfquery>
    <center><cfdump var = "#enclTable#"></center>   <<<  and here  >>>      enclTable is undefined
</cfif>

表单字段(从查询循环添加字段的id,名称和maxlen以及按钮的ID)...

<cfloop query ="getFormHeadings">
    <cfloop query = "getFormFields">
        <input type="input" class="form-control" id="#inpID#" name="#inpName#" maxlength="#inpLen#">
    </cfloop>
    <button class="btn btn-blue btn-block" type="submit" name="Add"  id="#enclTable#">
</cfloop>

该按钮位于另一个循环中,通过另一个查询

我在循环中尝试了这个并增加了x

<cfset variables["encl#x#"] = "#enclTable#">

但是当我把它放在

中时
<cfif structKeyExists(form,"Add")>

我收到x未定义的错误

#variables["enclTable" & x]#

也没用。我不确定我做错了什么。我可以创建动态变量,但我不能在它做任何事后引用它。很抱歉,如果有很多解释,我想彻底了解所有细节。

1 个答案:

答案 0 :(得分:0)

以下是我处理这种情况的方法。表格如下:

adjustPan

处理如下:

<cfoutput query="GetRecords">
<cfinput type="hidden" name="OldSpelling#DrugId#" value="#StandardSpelling#">
<cfinput type="hidden" name="OldInclude#DrugId#" value="#IncludeInReport#">
<cfinput type="hidden" name="OldCategory#DrugId#" value="#CategoryID#">
<tr>
<td>#DrugName#</td>
<td>

然后我对这些变量做了一些事情。