I’ve got some delimited data that I need to get into a Flex tree view (or some other kind of control that can display a hierarchy.) The data looks like this:
item1,groupA,mainGroup,root
item2,groupA,mainGroup,root
groupA,mainGroup,root
groupB,mainGroup,root
item3,groupB,mainGroup,root
item4,groupB,mainGroup,root
mainGroup,root
groupC,mainGroup,root
groupD,someOtherGroup,root
root
My flex app is connected to a jboss server that could potentially remove the root element (if necessary), but it really can’t build the tree structure (for a variety of reasons unrelated to this question.)
At any rate, that needs to translates to a tree like this (the actual order doesn’t matter, just the hierarchy.):
++ root
|-+ mainGroup
| |-+ groupA
| | - item1
| | - item2
| |-+ groupB
| | - item3
| | - item4
| |-+ groupC
|-+ someOtherGroup
| |-+ groupD
I know how to group flat data using a grouping collection, as is described here. But I haven’t had any luck figuring out a way to get flex to actually read/interpret the delimited format (without preprocessing it and building the correct structure myself.)
Thanks in advance for any suggestions.
I think pre-processing it is going to be the only way. What I mean by that is having a method you write that creates the GroupingCollection appropriately based on an algorithm which is based on your initial data.
The split method:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html#split()
GroupingCollection:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/GroupingCollection.html#grouping
Grouping:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/Grouping.html#fields
GroupingField:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/GroupingField.html
In looking through the docs they do have those groupingObjectFunction properties though for the life of me I can’t understand what that’s supposed to do.