嵌套的pound使用嵌套循环变量在变量周围进行标记

时间:2021-01-03 09:58:17

I have a table in a form with a loop around it that sets an index on all the name fields (form variables) that changes based on user input (user dictates how many tables get built). Once submitted, I take these variables and create a struct out of it. I know that a query object is already a struct, but I have to have each tables names unique, then put them into a struct which I can then rename to insert into the DB. My problem is how do I write this correctly and efficiently? I need to have a variable with a nested variable that is my index to make the name unique for each iteration through the loop. I have tried many combinations of pound signs and quotes and can't get it. If there is a better way to do this I am up for that too! dot notation

我有一个表格,周围有一个循环,在所有名称字段(表单变量)上设置一个索引,根据用户输入进行更改(用户指示构建多少个表)。提交后,我会获取这些变量并从中创建一个结构。我知道查询对象已经是一个结构,但我必须让每个表名都是唯一的,然后将它们放入一个结构中,然后我可以重命名以插入到数据库中。我的问题是如何正确有效地写这个?我需要一个带有嵌套变量的变量,这个变量是我的索引,通过循环使每个迭代的名称都是唯一的。我已经尝试了许多英镑符号和引号的组合,但无法得到它。如果有更好的方法可以做到这一点,我也是这样做的!点符号

  • cfset myStruct#i#=StructNew()>
  • cfset myStruct#i#.ID#i#="#form.myVarA#i##"
  • cfset myStruct#i#.s1#i#="#form.myVarB#i##"
  • cfset myStruct#i#.s2#i#="#form.myVarC#i##"

associated array notation

关联数组表示法

  • cfset myStruct#i#=StructNew()>
  • cfset myStruct#i#[ID#i#]="#form.myVarA#i##"
  • cfset myStruct#i#[s1#i#]="#form.myVarB#i##"
  • cfset myStruct#i#[s2#i#]="#form.myVarC#i##"

Any help is greatly appreciated.

任何帮助是极大的赞赏。

1 个解决方案

#1


This is the best reference you'll ever need to understand variables in CFML:

这是理解CFML中变量所需的最佳参考:

http://www.depressedpress.com/Content/Development/ColdFusion/Guides/Variables/Index.cfm

To answer your question, try this:

要回答您的问题,请尝试以下方法:

<cfset myStruct["#i#"] = structNew() />
<cfset myStruct["#i#"]["ID#i#"] = form["myVarA#i#"] />
<cfset myStruct["#i#"]["s1#i#"] = form["myVarB#i#"] />

This should give you:

这应该给你:

myStruct.1.id1 = form.myvarA1 myStruct.1.s11 = form.myvarB1

myStruct.1.id1 = form.myvarA1 myStruct.1.s11 = form.myvarB1

#1


This is the best reference you'll ever need to understand variables in CFML:

这是理解CFML中变量所需的最佳参考:

http://www.depressedpress.com/Content/Development/ColdFusion/Guides/Variables/Index.cfm

To answer your question, try this:

要回答您的问题,请尝试以下方法:

<cfset myStruct["#i#"] = structNew() />
<cfset myStruct["#i#"]["ID#i#"] = form["myVarA#i#"] />
<cfset myStruct["#i#"]["s1#i#"] = form["myVarB#i#"] />

This should give you:

这应该给你:

myStruct.1.id1 = form.myvarA1 myStruct.1.s11 = form.myvarB1

myStruct.1.id1 = form.myvarA1 myStruct.1.s11 = form.myvarB1