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

LVL 2
weeezlAsked:
Who is Participating?
 
orangachangConnect With a Mentor Commented:
Okay, had my coffee... Here it is...

<CFSCRIPT>
     Customer = StructNew();
     
    Tracks = ArrayNew(1);

         OneSong = StructNew();
           OneSong.Track = "1";
         OneSong.SongTitle = "If I Were A Bell";

     AddIt = ArrayAppend(Tracks, OneSong);
     
           AnotherSong = StructNew();
           AnotherSong.Track = "2";
         AnotherSong.SongTitle = "Stella By Starlight";
     
     AddIt = ArrayAppend(Tracks, AnotherSong);
     
     Customer.ShoppingCart = 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";
           OneCD.Tracks = Tracks;

     AddIt = ArrayAppend(Customer.ShoppingCart, OneCD);
     
</CFSCRIPT>
<cfdump var="#Customer.ShoppingCart#">
<cfoutput>
#Customer.ShoppingCart[1].Tracks[1].SongTitle#
</cfoutput>
0
 
orangachangCommented:
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#">
0
 
orangachangCommented:
Whoops, that's not right...
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
orangachangCommented:
Whoops, that's not right...
0
 
orangachangCommented:
The test...

<cfloop index="iTracks" from="1" to="#ArrayLen(Customer.ShoppingCart[1].Tracks)#">
     #Customer.ShoppingCart[1].Tracks[iTracks].SongTitle#<br>
</cfloop>
0
 
weeezlAuthor Commented:
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.
0
All Courses

From novice to tech pro — start learning today.