8 Replies Latest reply on Jun 17, 2009 6:42 PM by Michael Borbor

    Dataprovider for Flex Tree

    BosDog Level 1

      how do you dynamically populate nodes in the Flex tree with data from a database?

       

      For example... if I have a node for Groups and a database for names of groups... how would I populate the child nodes of the Groups folder with the names of the groups in the database?

        • 1. Re: Dataprovider for Flex Tree
          Michael Borbor Level 4

          The easiest way will be to generate a XML file, with the desire structure

          that you want your tree to show.

          • 2. Re: Dataprovider for Flex Tree
            BosDog Level 1

            i thought about that... i could prob do that with ColdFusion and put the file right into the folder that Flex can point to.

             

            but i'm having trouble finding out how to load the XML file in flex though... i think i saw some sample code on some demo somewhere but can't find it again.

            • 3. Re: Dataprovider for Flex Tree
              Michael Borbor Level 4

              Loading an XML is the easiest thing, you can use an HTTPService, or  a

              loader. If you want a sample look in the Flex LiveDocs or in TourDeFlex

              • 4. Re: Dataprovider for Flex Tree
                BosDog Level 1

                ok i'll try that out. so would this xmllistcollection which is declared in MXML

                 

                <mx:XMLListCollection id="treeData">
                        <mx:source>
                      <mx:XMLList>
                              <node label="Items">
                                  <node label="Open"/>
                                  <node label="In Progress"/>
                                  <node label="More Info"/>
                                  <node label="Closed"/>
                              </node>
                              <node label="Categories">
                                  <node label="Category 1"/>
                                  <node label="Category 2"/>
                              </node>
                              <node label="Groups">
                                  <node label="Group 1"/>
                                  <node label="Group 2"/>
                                  <node label="Group 3"/>
                              </node>           
                              <node label="Help"/>
                      </mx:XMLList>
                        </mx:source>
                </mx:XMLListCollection>

                 

                equal this in an XML file?

                              <node label="Items">
                                  <node label="Open"/>
                                  <node label="In Progress"/>
                                  <node label="More Info"/>
                                  <node label="Closed"/>
                              </node>
                              <node label="Categories">
                                  <node label="Category 1"/>
                                  <node label="Category 2"/>
                              </node>
                              <node label="Groups">
                                  <node label="Group 1"/>
                                  <node label="Group 2"/>
                                  <node label="Group 3"/>
                              </node>           
                              <node label="Help"/>

                 

                then  when i load the xml file i can just bind it to the flex tree?

                • 5. Re: Dataprovider for Flex Tree
                  Michael Borbor Level 4

                  Sure, you just need to verify that your xml file is well formed.

                  • 6. Re: Dataprovider for Flex Tree
                    BosDog Level 1

                    alright i'll experiment. you may be able to help me understand why this isn't working though... this is the route i was going down:

                     

                    i wanted to convert this mxml to actionscript and bind it to the tree (so i can add results from my dataprovider):

                     

                        <mx:XMLListCollection id="treeData">
                            <mx:source>
                          <mx:XMLList>
                                  <node label="Items">
                                      <node label="Open"/>
                                      <node label="In Progress"/>

                                  </node>
                          </mx:XMLList>
                            </mx:source>
                        </mx:XMLListCollection>

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                    and i was trying this code to make it bindable:

                     

                     

                    var stringData:String = '<node label="Items">' + '<node label="Open"/>' + '<node label="In Progress"/>'

                    + '</node>';

                     

                     

                     

                     

                     

                    var treeData= new XMLList(stringData);

                     

                    but when i use actionscript to create the treeData variable... and use {treeData} as the binding data... nothing shows in my tree.

                    • 7. Re: Dataprovider for Flex Tree
                      Michael Borbor Level 4

                      Use XML instead of String, and remove the ""

                      • 8. Re: Dataprovider for Flex Tree
                        Michael Borbor Level 4

                        You'll be better reading this section in the Flex LiveDocs

                        http://livedocs.adobe.com/flex/3/html/13_Working_with_XML_01.html