10 Replies Latest reply on Feb 16, 2007 12:26 PM by jedale

    Tree

    YAHA1
      Hello,

      Does someone know a good way of saving the information from the tree component (names of nodes and their hierarchy) into a database? The same information will have to be pulled out of the database later in the application.

      P.S.
      I am trying to design an admin system for a menu on the website, which is very similar to the tree (the menu entries have sub entries).

      Please share your thoughts and ideas.
        • 1. Tree
          jedale
          I made a quick function to do this take a look........

          I have also posted a question on manually sorting a tree as well. This might be of use to you. Its not totally working but hopefully it will soon

          Jeff
          • 2. Re: Tree
            BKBK Adobe Community Professional & MVP
            We of course have to first convert Jedale's code from Java to CFML.



            • 3. Re: Tree
              Stressed_Simon
              That is actually Actionscript not Java
              • 4. Tree
                BKBK Adobe Community Professional & MVP
                That is actually Actionscript not Java
                Oh, yes, var var not Java. Sorry, Simon, didn't look that far. I had something else in mind. I am translating it into Actionscript and CFML.






                • 5. Re: Tree
                  YAHA1 Level 1
                  I undestand the algorithm . . . However, the Coldfusion code would help a lot . . .
                  • 6. Tree
                    jedale Level 1
                    First off you have to have a flash form so in your <cfform> tag make sure you have a format="flash" somewhere.

                    The actionscript goes between cfformitem tags:
                    <cfformitem type="script">
                    ...actionscript here...
                    </cfformitem>

                    and then you call the actionscript by:

                    <cfinput type="button" name="EOWSort" width="110" disabled="true" value="Save Sort Order" onClick="alert(makeTreeList(Programs));">

                    Where Programs is the name of my tree, you need to change this to the name you gave your own tree.

                    An alert will pop up in a flash form and tell you the order of the items.

                    Hopefully that helps
                    • 7. Re: Tree
                      YAHA1 Level 1
                      I think i solved the problem of building the tree from the database . . .

                      used the following code . . .

                      <cfquery name="Pull_Child" datasource="blahblah">
                      Select Category, ParentName
                      From menu
                      Where ParentLevel is not null
                      </cfquery>


                      <cfloop query="Pull_Child">
                      <cftreeitem value = "#Category#" parent = "#ParentName#" queryAsRoot = "Main Menu" expand = "no">
                      </cfloop>


                      the table contains (Category Name - Name of a node, Parent Name - name of the parent node, ParentLevel - level of the node in the tree)

                      Now I am facing another task - analyzing the database and outputting the correct html code for the menu . . . (if you have any suggestions on this, please post)

                      Thanks to all of you for help . . .
                      • 8. Re: Tree
                        BKBK Adobe Community Professional & MVP
                        > I think i solved the problem of building the tree from the database . . .
                        I had thought all along you wished instead to build a database from a tree . That is, to save tree information into the database.

                        • 9. Re: Tree
                          BKBK Adobe Community Professional & MVP
                          Jedale, I have an applet that has some of your code. However, I am not too sure about getLength() as a function of a tree, and of the negative argument in treelist.slice(0, -1). What do you want the function makeTreeList to do?

                          • 10. Re: Tree
                            jedale Level 1
                            I made the function to get all of the data values in the tree to make into a list. This list is then remoted to a cfc so that the order of the tree is preserved (I also have a sorting function that is not yet working completely and have posted a question at this forum). So once the user comes to my page the tree is populated via remoting in the correct sequence. That was my intention in using this code, but the hang up is on the tree sorting correctly.

                            I used the slice command to remove the last comma in the list. I know its not really needed but I like to keep things nice and neat. Additionally, the getlength() function just provides the number of items within a tree, combobox, grid. Sometimes a simple ".length" will work for certain components.

                            I'm sure you knew this but my example to get the actionscript to run with the onclick function should have an input argument of the name of your cftree. I will edit this.