1 Reply Latest reply on Jan 16, 2008 2:33 PM by shawnyale

    Filtering XMLListCollection to a Tree Control

    shawnyale Level 1
      Second issue:
      Ive followed the documentation precisely but still cant get my tree control to filter correctly. I want to filter the XML based on an attribute in the node
      <customer color="blue">
      <customer color="green"/>
      <customer color="red">
      <customer color="blue"/>

      I want to filter the above xml so that if I search for customers with the color = 'blue" then nested or not, the elements will show in my tree control.

      This is my filter:

      // This is called when a user types in a color value
      protected function filterByColor():void
      dataSourceXMLListCollection.filterFunction = colorFilter;
      protected function colorFilter(item:Object):Boolean
      return item.@color == 'blue';

      <mx:Tree id="tree" dataProvider="dataSourceXMLListCollection" labelField="label"/>

      The tree never refreshes even though it is data bound to the XMLListCollection. And it looks like the filter function is never processing all of the individual nested nodes... the entire XML is getting passed as the "item" for the filter function instead of each individual node. So when I watch the colorFilter(item:Object) with a trace I get

      item = <customer color="blue">
      +<customer color="green"/>
      +<customer color="red">
      <customer color="blue"/>

      and the trace itself showed the entire XMLListCollection instead of each individual item.

      Can anyone offer any insight as to what Im doing wrong?
      All of my XML is well formed. Just nested.