7 Replies Latest reply on Jun 17, 2009 11:06 PM by leybniz

    Dynamically populating an XMLList

    BosDog Level 1

      How would i go about dynamically populating a specific node section with database values? See code below that is static. I'd like for example the Groups node to be populated with the names of groups in my database. I use Coldfusion as the server side language so I understand dataproviders but I cannot add a dataprovider in the node tag:

       

          <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>

        • 1. Re: Dynamically populating an XMLList
          leybniz Level 4

          It would be better for you to assemble whole tree from the parts, dynamic ones compose out of database values, static ones out of static consts etc.

           

          If you want to locate that 'Groups' node you could use this kind of syntax:

           

          public var tree:XML = <root>

          <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"/>

          </root>;

           

          public var groupsNode:XML = tree.descendants(hasOwnProperty('@label') && @label == 'Groups')[0];

          • 2. Re: Dynamically populating an XMLList
            BosDog Level 1

            i couldnt get that code to work. does it matter that i'm declaring the tree in mxml rather than actionscript? your code looks like its all actionscript and part of a class?

             

            i added this code to my app based on yours and under my init method:

             

            var groupsNode:XML = treeData.descendants(hasOwnProperty('@label') && @label == 'Groups')[0]; 

             

            but i get a compile error:

            "Attemped access of inaccessible property label through a reference with static type main."

            • 3. Re: Dynamically populating an XMLList
              leybniz Level 4

              oh, I'm really sorry for mistype, it should be like this:

               

              var groupsNode:XML = tree.descendants().(hasOwnProperty('@label') && @label == 'Groups')[0];

               

               

               

               

               

               

               

               

               

              • 4. Re: Dynamically populating an XMLList
                BosDog Level 1

                hmmm... maybe im missing something but how do i populate the values based on the database values?

                • 5. Re: Dynamically populating an XMLList
                  leybniz Level 4

                  hmm, maybe like this?

                   

                  var databaseValues:Array = ['db value 1', 'db value 2', 'db value 3'];

                   

                  for each (var item:XML in groupsNode..node)

                       item.@label = databaseValues[item.childIndex()];

                   

                  If you feel this message answers your question or helps, please mark it respectively

                  • 6. Re: Dynamically populating an XMLList
                    BosDog Level 1

                    hi Alex,

                    am i still using my mx:XMLListCollection? Or are you suggessting I somehow create an XML list via actionscript? i dont think the syntax you gave me will apply to my XMLListCollection in the previous posts.

                    • 7. Re: Dynamically populating an XMLList
                      leybniz Level 4

                      it would be better for you to go with the native XML type for maintaining your tree structure.