Am currently working on a Tree control, and being my first time to delve into this, I need your inputs and advice.
My tree control is retrieving data from a .NET web service. My .NET webservice returns a string which is parsed from a dataset via the command DataSet.GetXML method.
Function MyFunc() as String
'Populate the dataset here
'.......
Return DataSet.GetXML()
End Function
In my flex application, I am converting the string value returned by the webservice into an XML:
private var _xmlMyData:XML;
private function myResultHandler(event:ResultEvent) :void
{
_xmlMyData = XML(event.result);
// This script to view the XML data in Text Area
var strData:String = String(event.result);
taData.text = strData;
}
Which I am then passing to my xmlListCollection control
<mx:XMLListCollection id="xmllc_myData" source="{_xmlMyData.Table}" />
<mx:TextArea id="taData" width="300" height="100" />
Then binding to my tree control:
<mx:Tree id="treeOffshore" dataProvider="{xmllc_myData}" labelField="DESCN" showRoot="false">
</mx:Tree>
When viewing the data in the text area control, I have the following:
<NewDataSet>
<Table>
<CODE>A1</CODE>
<DESC>Area One</DESC>
</Table>
<Table>
<CODE>B2</CODE>
<DESC>Base Two</DESC>
</Table>
<Table>
<CODE>C4</CODE>
<DESC>Class Four</DESC>
</Table>
<Table>
<CODE>D8</CODE>
<DESC>Demo Eight</DESC>
</Table>
</NewDataSet>
This is how the treeview renders:
Area One
A1
Area One
Base Two
B2
Base Two
Class Four
C4
Class Four
Demo Eight
D8
Demo Eight
What I want is to be able to define the Description only at the first level only:
Area One
Base Two
Class Four
Demo Eight
The next thing that I need to accomplish is that the second level of the treeview should actually be populated based on the CODE from the first level.
For example:
Area One
Sub Item Area One
Sub Item Area Two
Base Two
Sub Item Base Two
Sub Item Base Three
Sub Item Base Four
Class Four
Sub Item Class Four
Demo Eight
Sub Item Demo Eight
Sub Item Demo Nine
Sub Item Demo Ten
Sub Item Demo Eleven
I am quite new in this tree control thing (as well as flex) and have limited grasp of the concepts to be able to accomplish this.
I am thinking either of modifying the XML data which I originally retrieve and probably insert the sub items per each node, although I am in a bind of how to accomplish the same.
On the other hand, to give some of you further details, the treeview data would actually be coming from three tables where the table 1 is the base table, and the table 2 contains the children of table 1 and table 3 contains children data from table 3.
I would sincerely appreciate your inputs on this. I am foraying into the world of Flex and this is quite a make or break scenario towards embracing this technology in our organization.
Thanks and hoping to get some good advice on how to accomplish this.
Regards,