3 Replies Latest reply on Apr 29, 2006 9:37 AM by BKBK

    Traverse A Nested Struct

    Neo Rye Level 1
      Any thoughts on the quickest way to the last struct in a nested struct without knowing the keys or how deep it's nested? And of course it could branch much like trying to traverse a tree.
        • 1. Re: Traverse A Nested Struct
          BKBK Adobe Community Professional & MVP
          > last struct in a nested struct
          Strictly speakly, that doesn't exist. By default, Coldfusion does not sort the keys of a structure. The following code gives a sorted list of keys, some of which are themselves structures.

          • 2. Re: Traverse A Nested Struct
            Neo Rye Level 1
            I wasn't looking for an alphabetical list, just trying to get to the inner most nested struct the quickest. In you example, how would I get the value of employee.phone.office.ext without previousley knowing that phone.office.ext existed and I only know about employee. I could iterate over it with some type of iterator hasNext(), but was wondering if there was a quicker way.

            <cfset employee.name.first = "Mary">
            <cfset employee.name.last = "Smith">
            <cfset employee.position = "Boss">
            <cfset employee.phone.home = "111-2222-33333">
            <cfset employee.phone.office.ext = "444">
            <cfset employee.phone.office.number>
            • 3. Re: Traverse A Nested Struct
              BKBK Adobe Community Professional & MVP
              Oh, so you require the value of the "deepest" key(s) in the structure. The only method I know of is indeed to iterate across the keys/substructures, perhaps posing a question with isStruct() at every stage.