4 Replies Latest reply on Jul 6, 2010 5:56 AM by BhaskerChari

    Make a grouping with Mx:repeater and XML (like a tree)

    Jotajota-br

      Hi everybody?

      What's up?

       

      Thank you for you atention. I have a simple problem with mx:repeater.

       

      I have a xml and I need show this xml  inside a window in a grouping model:

       

      I retrieve in database every cities and every states. The xml returned is the same below struture:

       

      <states>
          <state>
              <name_state></name_state>
              <code_state></code_state>
              <cities>
                  <city>
                      <name_city>
                      <population_city>
                  <city>
              </cities>
          </state>
      </states>

       

      But I need show in other view, as the below struture:

       

      State x:

      City one

      City two

      City tree

       

      State y:

      City four

      City five

      City six

       

      Can you understand me?

      Can you help me how i need to do it with repeater?

       

      I tried to use this sample but this struture is very simple and i Can't finished

      http://blog.flexexamples.com/2009/10/08/toggling-child-recycling-on-a-repeater-in-flex/#mo re-1987

       

       

      Thank you very much.

        • 1. Re: Make a grouping with Mx:repeater and XML (like a tree)
          UbuntuPenguin Level 4

          You would have to nest your repeaters.  Basically almost like item renderers , passing to them an object made from the xml.

          • 2. Re: Make a grouping with Mx:repeater and XML (like a tree)
            Jotajota-br Level 1

            Thanks UbuntuPenguin

            Can you give some sample?

            I had problem with passing to repeaters the object made from the xml.

             

            thanks!

            • 3. Re: Make a grouping with Mx:repeater and XML (like a tree)
              BhaskerChari Level 4

              Hi Paulo Roberto de Camargo Mello Junior,

               

              Here is the code you need....

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="convertXMLtoArrayCollection()">
              <mx:Script>
                <![CDATA[
                 import mx.collections.ArrayCollection;
                 import mx.rpc.xml.SimpleXMLDecoder;
                 private var arrayCollection:ArrayCollection = new ArrayCollection();
                
                 private function convertXMLtoArrayCollection():void
                 {
                  var xml:XML = new XML(xmlStates.toString());
                  var xmlDoc:XMLDocument = new XMLDocument(xml);
                  var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
                  var resultObj:Object = decoder.decodeXML(xmlDoc);
                  if(resultObj.states.state is ArrayCollection)
                  {
                   arrayCollection = resultObj.states.state as ArrayCollection;
                  }
                  else if(resultObj.states.state is Object)
                  {
                   arrayCollection.addItem(resultObj.states.state);
                  }
                  rptMain.dataProvider = arrayCollection;
                 }
                ]]>
              </mx:Script>
              <mx:XML xmlns="" id="xmlStates">
                <states>
                    <state>
                        <name_state>State x:</name_state>
                        <code_state>X</code_state>
                        <cities>
                            <city>
                                <name_city>City One</name_city>
                                <population_city>20000</population_city>
                            </city>
                            <city>
                                <name_city>City Two</name_city>
                                <population_city>10000</population_city>
                            </city>
                            <city>
                                <name_city>City Three</name_city>
                                <population_city>80000</population_city>
                            </city>
                        </cities>
                    </state>
                    <state>
                        <name_state>State y:</name_state>
                        <code_state>X</code_state>
                        <cities>
                            <city>
                                <name_city>City Four</name_city>
                                <population_city>50000</population_city>
                            </city>
                            <city>
                                <name_city>City Five</name_city>
                                <population_city>40000</population_city>
                            </city>
                            <city>
                                <name_city>City Six</name_city>
                                <population_city>70000</population_city>
                            </city>
                        </cities>
                    </state>
                </states>
              </mx:XML>
              <mx:VBox verticalGap="0" horizontalAlign="center">
                <mx:Repeater id="rptMain">
                 <mx:VBox verticalGap="0">
                  <mx:Label fontWeight="bold" fontSize="15" text="{rptMain.currentItem.name_state}"/>
                  <mx:VBox verticalGap="0">
                   <mx:Repeater id="rptCities" dataProvider="{rptMain.currentItem.cities.city}">
                    <mx:Label  fontSize="13" text="{rptCities.currentItem.name_city}"/> 
                   </mx:Repeater>  
                  </mx:VBox>
                 </mx:VBox>
                </mx:Repeater>
              </mx:VBox>

              </mx:Application>

               

              If this post answers your question or helps, please kindly mark it as such.


              Thanks,

              Bhasker Chari

              • 4. Re: Make a grouping with Mx:repeater and XML (like a tree)
                BhaskerChari Level 4

                Hi  Paulo Roberto de Camargo Mello Junior,

                 

                Have you tested it...? Is it working for you..???

                 

                 

                Thanks,

                Bhasker Chari