Link to home
Start Free TrialLog in
Avatar of weeezl
weeezl

asked on

Working with Nested Arrays / Structures

I've been trying to create a complex data management system using nested arrays and structures. I've been using the example here:

http://www.macromedia.com/v1/handlers/index.cfm?id=18894&method=full

So far, I understand how to create an array that references a structure like this:

<CFSCRIPT>
     MyCart = ArrayNew(1);

          OneCD = StructNew();
          OneCD.Title = "Cookin at the Plugged Nickel";
          OneCD.Artist = "Miles Davis";
          OneCD.Genre = "Jazz";
          OneCD.Cost = "15.00";
          OneCD.Quantity = "1";

     AddIt = ArrayAppend(MyCart, OneCD);
     
          AnotherCD = StructNew();
          AnotherCD.Title = "Lady in Satin";
          AnotherCD.Atrist = "Billie Holiday";
          AnotherCD.Genre = "Blues";
          AnotherCD.Cost = "14.00";
          AnotherCD.Quantity = "2";
         
     AddIt = ArrayAppend(MyCart, AnotherCD);
</CFSCRIPT>

The link above also makes reference to a nested array that is more than one level deep. My question is, can someone give me an example of how to build a structure like this?

Customer.ShoppingCart[2].Tracks[3].SongTitle

Avatar of orangachang
orangachang

Weeez,

That's way to complicated even if you could figure it out.

How about this:

<CFSCRIPT>
    MyCart = ArrayNew(2);

         OneCD = StructNew();
         OneCD.Title = "Cookin at the Plugged Nickel";
         OneCD.Artist = "Miles Davis";
         OneCD.Genre = "Jazz";
         OneCD.Cost = "15.00";
         OneCD.Quantity = "1";
     
     SongTitle = ArrayNew(2);
     
     Album = StructNew();
     Album.Track = "1";
     Album.SongTitle = "Stella By Starlight";

    MyCart[1][1] = OneCD;
MyCart[1][2] = Album;
     
</CFSCRIPT>
<cfdump var="#MyCart#">
Whoops, that's not right...
Whoops, that's not right...
ASKER CERTIFIED SOLUTION
Avatar of orangachang
orangachang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The test...

<cfloop index="iTracks" from="1" to="#ArrayLen(Customer.ShoppingCart[1].Tracks)#">
     #Customer.ShoppingCart[1].Tracks[iTracks].SongTitle#<br>
</cfloop>
Avatar of weeezl

ASKER

Wheee!

Thanks for your help. Just learning structs in arrays and I assume it has to drive you crazy for a while before you get it.