Jon,

This method does work, but there's a more efficient and faster way to
process this. Instead of using the Evaluate() function, use either of the
following two methods:

<cfloop collection="#parentStructure#" item="key">
    <cfloop collection="#parentStructure[key]#" item="key2">
        <cfoutput>#key2# #parentStructure[key][key2]#</cfoutput><br>
    </cfloop>
</cfloop>

or

<cfloop collection="#parentStructure#" item="key">
    <cfloop collection="#parentStructure[key]#" item="key2">
        <cfoutput>#key2# #StructFind(parentStructure[key],
key2)#</cfoutput><br>
    </cfloop>
</cfloop>

The Evaluate() function is very CPU expensive, and it's best to try and
avoid using it when possible.

-Dan
+--------+---------------------------+
|   name | Dan G. Switzer, II        |
|company | PengoWorks.com            |
|    www | http://www.pengoworks.com |
| mailto | [EMAIL PROTECTED]   |
+--------+---------------------------+


-----Original Message-----
From: Jon Hall [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 18, 2000 6:38 PM
To: CF-Talk
Subject: looping over structures

Well I had a problem, but as I was typing the below I figured it out.
Instead of deleting my email though, I thought I would send it anyway in
case this helps anyone else with nested structures...

I have a set of nested structures that I dynamically create from a query, so
I only know the top level structure name.
I need to know the values of the nasted structure keys are with out knowing
the structures name. I'll do a quick example.

<cfset parentStructure = StructNew()>
<cfloop...>
    <cfset temp = StructNew()>
    <cfset temp[keyval1] = 1>
    <cfset temp[keyval2] = 2>
    ...and so on
        <cfset parentStructure[keyval1] = temp>
</cfloop>

So I have nested the structures now and I can refer to the key values if I
know what the value of 'keyval1' is.
I can also get a list of all of the keys in 'parentStructure' with
StructKeyList().

My problem was that when I looped over the StructKeyList and then using that
value in my second loop over the collection, the variable was not evaluating
correctly.

<cfloop list="StructKeyList(parentStructure)" index="struct">
<cfloop collection="#parentStructure[struct]#" item="key">

This is where I had my problem. Dot Notation does not work in the second
collection loop, and looping over the StructKeyList was unnecessary.

Here is what works very well.

<cfloop collection="#parentStructure#" item="key">
    <cfloop collection="#parentStructure[key]#" item="key2">
        <cfoutput>#key2# #evaluate("parentStructure" & "." & "#key#" & "." &
"#key2#")#</cfoutput><br>
    </cfloop>
</cfloop>

Anyway, my problem is solved. If anyone has a better way to do this, I'm all
ears

jon
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to