FYI, you can replace this syntax:
    <cfset datacontainer[aid].container.1 = scontainer1>    

with this:
    <cfset datacontainer[aid].container[1] = scontainer1>     

and that should help you manipulate things with data coming from a
query.

But if the "id" is really the "primary key" then why make datacontainer
an array at all? Make it a struct and put each record in the struct
using the key value... This will make it easy to find the same
record/struct later when you want to connect something to it (by adding
the new "something" to a struct contained in the parent node).  (Maybe
you're using arrays because you want to preserve the order of siblings..
like 2, 3 and 9 in your example.  An array makes sense for this, but a
maintaining another single struct that contains all nodes by id is handy
for that lookup capability.)

I bet someone on the list will be able to point you at code for loading
hierarchical data and you'll see the same kind of thing that you are
trying to do, pretty much all based on Structs.

Thanks
        Mark

-----Original Message-----
From: [EMAIL PROTECTED] [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 25, 2007 3:25 PM
To: CF-Talk
Subject: Infinite Structure Looping

Hello, 

I'm trying to set up a structure based on unique values in a flat SQL
database with unique id's.  And then output values in the structure in a
hierarchy kind of like:

    1
    |
 2  3  9
    |
    4  5  6
       |
       7  8


I believe can loop through and exhaust all the values based on a lookup
list of what structure has been outputted.  But I'm having a problem
thinking about the natural flow of the output and joining up the parent
with children in the hierarchy.  

Is this possible or very easy?  I'm basically wanting a cfdump type
output that I can manipulate the HTML/javascript.  The below code is how
I want to set up the structure.  Any thoughts would be great.

<cffunction name="maketextform" access="public">
    <cfargument name="id" required="Yes" type="numeric">
    <cfargument name="value" required="no" default="">
    <cfargument name="js" required="no" default="">
    <cfset this.id = arguments.id>
    <cfset this.value = arguments.value>
    <cfset this.js = arguments.js>
    <cfset  starttag = '<input type="text" id = "#this.id#"
value="#this.value#" onclick="#this.js#">'>
    <cfreturn starttag>
</cffunction>

<cfparam name="datacontainer" default="#arraynew(1)#">
       
    <cfset container = structnew()>    
    <cfset tmp = arrayappend(datacontainer,container)>
    <cfset aid = arraylen(datacontainer)>
    <cfset datacontainer[aid].container.name = "IP">
    <cfset scontainer1 = structnew()> 
    <cfset datacontainer[aid].container.1 = scontainer1>    
    <cfset datacontainer[aid].container.1.id = 1>
    <cfset datacontainer[aid].container.1.value = "I could grab this
from a structure from query2structure ripper 1">
    <cfset datacontainer[aid].container.1.name = 'Matter'>
    <cfset datacontainer[aid].container.1.js= "alert('dog')">
    <cfset datacontainer[aid].container.1.field =
#maketextform(datacontainer[aid].container.1.id,datacontainer[aid].conta
iner.1.value,datacontainer[aid].container.1.js)#>

    <cfset scontainer2 = structnew()>     
    <cfset datacontainer[aid].container.1.2 = scontainer2>    
    <cfset datacontainer[aid].container.1.2.id = 2>
    <cfset datacontainer[aid].container.1.2.value = "I could grab this
from a structure from query2structure ripper 2">
    <cfset datacontainer[aid].container.1.2.name = 'Matter'>
    <cfset datacontainer[aid].container.1.2.js= "alert('dog')">
    <cfset datacontainer[aid].container.1.2.field =
#maketextform(datacontainer[aid].container.1.2.id,datacontainer[aid].con
tainer.1.2.value,datacontainer[aid].container.1.2.js)#>
    
    
    <cfset scontainer3 = structnew()>     
    <cfset datacontainer[aid].container.1.2.3 = scontainer3>    
    <cfset datacontainer[aid].container.1.2.3.id = 3>
    <cfset datacontainer[aid].container.1.2.3.value = "I could grab this
from a structure from query2structure ripper 3">
    <cfset datacontainer[aid].container.1.2.3.name = 'Matter'>
    <cfset datacontainer[aid].container.1.2.3.js= "alert('dog')">
    <cfset datacontainer[aid].container.1.2.3.field =
#maketextform(datacontainer[aid].container.1.2.3.id,datacontainer[aid].c
ontainer.1.2.3.value,datacontainer[aid].container.1.2.3.js)#>
    
    <cfset scontainer5 = structnew()>     
    <cfset datacontainer[aid].container.1.2.5 = scontainer5>    
    <cfset datacontainer[aid].container.1.2.5.id = 5>
    <cfset datacontainer[aid].container.1.2.5.value = "I could grab this
from a structure from query2structure ripper 5">
    <cfset datacontainer[aid].container.1.2.5.name = 'Matter'>
    <cfset datacontainer[aid].container.1.2.5.js= "alert('dog')">
    <cfset datacontainer[aid].container.1.2.5.field =
#maketextform(datacontainer[aid].container.1.2.5.id,datacontainer[aid].c
ontainer.1.2.5.value,datacontainer[aid].container.1.2.5.js)#>
    
    <cfset scontainer4 = structnew()>     
    <cfset datacontainer[aid].container.1.4 = scontainer4>    
    <cfset datacontainer[aid].container.1.4.id = 4>
    <cfset datacontainer[aid].container.1.4.value = "I could grab this
from a structure from query2structure ripper 4">
    <cfset datacontainer[aid].container.1.4.name = 'Matter'>
    <cfset datacontainer[aid].container.1.4.js= "alert('dog')">
    <cfset datacontainer[aid].container.1.4.field =
#maketextform(datacontainer[aid].container.1.4.id,datacontainer[aid].con
tainer.1.4.value,datacontainer[aid].container.1.4.js)#>              
     
<cfdump var="#datacontainer#">

Thanks! 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Check out the new features and enhancements in the
latest product release - download the "What's New PDF" now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:289441
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to