tags:

views:

114

answers:

2

How do I get a Flex tree to display only specific XML nodes?

A sample of the XML data is below. Only the Grouper and Product elements should be displayed as branch and leaf nodes respectively; the Name elements should not be displayed. I can't use XSL or e4x to modify the XML as the Name elements' text is used as the label for the Grouper and Product tree nodes. Also, I cannot move the Name element to be an attribute as it needs to include a CDATA section.

It looks like using a custom TreeDataDescriptor is the way forward but I cannot find any examples of using one with XML.

Any advice appreciated.

Thanks,

Al H.

 <Grouper Type="ProductHeading" Id="" icon="drugIcon">
      <Name>ASPAV</Name>
      <Product Id="1002081" icon="genericIcon">
           <Name>ASPAV dispersible tablet</Name>
      </Product>
 </Grouper>

 <Grouper Type="ProductHeading" Id="" icon="drugIcon">
      <Name>ASPELLIN</Name>

      <Product Id="1005755" icon="genericIcon">
           <Name>ASPELLIN liniment</Name>
      </Product>
 </Grouper>

A: 

Start by creating a custom descriptor that extends the DefaultDataDescriptor class, which has XML support out of the box. I would start by overriding the following methods:

isBranch getChildren hasChildren

cliff.meyers
It's the overriding I'm stuck on. For example, what would my getChildren method look like?
Alistair77
A: 

Finally found the solution thanks to David Arno's great article (title is " How to filter all nodes of a Flex Tree component ").

Seems like a lot of people have asked this question but this is the only solution I've found - and it works great ;)

Alistair77