1 Reply Latest reply on Mar 29, 2007 11:28 AM by peterent

    Tree with ArrayCollection

    frenchi30 Level 1
      Hi all,

      I was wondering if someone could please point me in the correct direction.

      I have an HTTPService that I am using with a datagrid, the Service's data is loaded into an ArrayCollection and I filter the ArrayCollection with a filterFunction. All works great.

      I now want to take the same ArrayCollection and load certain elements of the data into a tree. This is where I am getting errors.

      The xml:
      <?xml version="1.0" encoding="utf- 8"?>
      <build>
      ....<item id="1">
      ........<name>Name</name>
      ........<area> Chicago </area>
      ........<status>Avail.</status>
      ........<spec>1264</spec>
      ........<size>40</size>
      ....</item>
      ....<item id="2">
      ........<name>Name</name>
      ........<area> New York </area>
      ........<status>Avail.</status>
      ........<spec>1264</spec>
      ........<size>49</size>
      ....</item>
      </build>

      I want to display in the tree the area(s) as the folder and the name under it as a leaf(s). All I managed to do is a labelFunction that returns the area, and populates the tree as leafs. I am assuming, I will have to create a custom function?

      private function trModels(item: Object):String{
      return item.community;
      }

      I would like the tree to look like this:
      ....>Chicago
      ........>Name
      ....>New York
      ........>Name
      ....>Miami
      ........>Name

      Now, all the docs I could find tell me to use the result on the httpservice as e4x and filter the data that way for the tree, but when I specify e4x as resultFormat I get an error and it breaks my filtering on the datagrid...: Error #1034: Type Coercion failed: cannot convert XMLList@2d03541 to mx.collections. ArrayCollection.

      Can anyone point me in the correct direction please? There must be a way to filter data that is not "tree" friendly..

      thank-you
        • 1. Re: Tree with ArrayCollection
          peterent Level 2
          You can use an ArrayCollection of ArrayCollections (a hierarchical collection) with the Tree.

          [ {label:"Cities", children: [{label:"Chicago", children:[{label:"Name"}]}, {label:"Boston",children:[{label:"Name"}]}, ... ]}, ... ]

          The trick is to use "children" as the property name for the nested arrays.