R – How to get the item parent in a flex tree when using nested objects as data provider

apache-flexdataprovidertree

I have a Flex tree with an ArrayCollection as data provider. The collection holds an array of CategoryVO objects. Each object can have another array of CategoryVO objects inside it's "child" attribute. This way the tree displays the data correctly.

Now I want to get the parent of a specific item, e.g. tree.selectedItem. Using XML as data provider the item parent is available through the parent() method. But I can't convert my data to XML. How can I get an item's parent? Perhaps using the tree's dataDescriptor?

Best Answer

I just found out how to solve my problem :) The tree offers a getParentItem(item:Object) method that returns the parent item of the item. Notice that this function returns null for top level items.