Answered
Dynamic Nested Structs
I'm looking for a way to build a dynamic nested structure in
cfscript using a for loop. Something like:
<cfset MyStruct = StructNew()>
<cfset MyStruct["A"] = StructNew()>
<cfset MyStruct["A"]["B"] = StructNew()>
<cfset MyStruct["A"]["B"]["C"]= StructNew()>
<cfset MyStruct["A"]["B"]["C"]["D"]= StructNew()>
<cfset MyStruct["A"]["B"]["D"]["R"]= StructNew()>
The depth of the nested structure is unknown, 2 to 1000 and the A, B, C, D, R are all unknown. I have no problem creating the first struct MyStruct["A"], but can't seem to add the second + nested struct to the first dynamically in my loop. Seems like I want to concatenate each nested structure to the previous structure as I go.
Any thoughts?
<cfdump var="#MyStruct#">
<cfset MyStruct = StructNew()>
<cfset MyStruct["A"] = StructNew()>
<cfset MyStruct["A"]["B"] = StructNew()>
<cfset MyStruct["A"]["B"]["C"]= StructNew()>
<cfset MyStruct["A"]["B"]["C"]["D"]= StructNew()>
<cfset MyStruct["A"]["B"]["D"]["R"]= StructNew()>
The depth of the nested structure is unknown, 2 to 1000 and the A, B, C, D, R are all unknown. I have no problem creating the first struct MyStruct["A"], but can't seem to add the second + nested struct to the first dynamically in my loop. Seems like I want to concatenate each nested structure to the previous structure as I go.
Any thoughts?
<cfdump var="#MyStruct#">
