[flexcoders] Tree Control Populating from Database via XMLListCollection
Hi FlexCoders, 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. 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 CODEA1/CODE DESCArea One/DESC /Table Table CODEB2/CODE DESCBase Two/DESC /Table Table CODEC4/CODE DESCClass Four/DESC /Table Table CODED8/CODE DESCDemo 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 The sub-items would be retrieved from the database based on the parent code (i.e Demo Eight = D8, Class Four = C4... etc.) 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 think I can manage to make one SQL statement to be able to retrieve the data for the whole treeview but I think that would be very complicated especially in the part where parsing the XML goes. 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 hear from all of you soon. Regards, Angelo
Re: [flexcoders] Tree Control Populating from Database via XMLListCollection
Anyone?? Thanks. From: Angelo Anolin angelo_ano...@yahoo.com To: flexcoders@yahoogroups.com Sent: Wednesday, 19 August, 2009 20:53:49 Subject: [flexcoders] Tree Control Populating from Database via XMLListCollection Hi FlexCoders, 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. 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:ResultEven t) :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:XMLListCollectio n 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 CODEA1/CODE DESCArea One/DESC /Table Table CODEB2/CODE DESCBase Two/DESC /Table Table CODEC4/CODE DESCClass Four/DESC /Table Table CODED8/CODE DESCDemo 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 The sub-items would be retrieved from the database based on the parent code (i.e Demo Eight = D8, Class Four = C4... etc.) 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 think I can manage to make one SQL statement to be able to retrieve the data for the whole treeview but I think that would be very complicated especially in the part where parsing the XML goes. 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 hear from all of you soon. Regards, Angelo
RE: [flexcoders] Tree Control Populating from Database via XMLListCollection
If you want a tee structure that is different from the xml structure, you can use a custom datadescriptor. If you just want to control the displayed labels, you can use a label function. I would be inclined to manipulate the xml into the structure I want for the tree, just because I have not done a custom dataDescriptor yet. Tracy Spratt, Lariat Services, development services available _ From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf Of Angelo Anolin Sent: Wednesday, August 19, 2009 11:12 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Tree Control Populating from Database via XMLListCollection Anyone?? Thanks. _ From: Angelo Anolin angelo_ano...@yahoo.com To: flexcoders@yahoogroups.com Sent: Wednesday, 19 August, 2009 20:53:49 Subject: [flexcoders] Tree Control Populating from Database via XMLListCollection Hi FlexCoders, 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. 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:ResultEven t) :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:XMLListCollectio n 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 CODEA1/CODE DESCArea One/DESC /Table Table CODEB2/CODE DESCBase Two/DESC /Table Table CODEC4/CODE DESCClass Four/DESC /Table Table CODED8/CODE DESCDemo 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 The sub-items would be retrieved from the database based on the parent code (i.e Demo Eight = D8, Class Four = C4... etc.) 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 think I can manage to make one SQL statement to be able to retrieve the data for the whole treeview but I think that would be very complicated especially in the part where parsing the XML goes. 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 hear from all of you soon. Regards, Angelo