3 Replies Latest reply on Jun 23, 2006 3:59 PM by ntsiii

    Nested XML into comboBox

    leotemp Level 1
      Well as stupid as this sounds I can populate a datagrid from a dynamic xml source(ASP) using HTTPservice but a basic lack of understanding is preventing me from using this data in a comboBox :(
      Below is my application source that works for populating the datagrid in it, but when the data is used in the comboBox as it's dataprovider the value is "[object][object]" Ive tried a bunch of stuff but I think im conceptualy misunderstanding something about retreiving nested values...

      --MY BROKEN EXAMPLE---

      --XML-output-by-asp-document--------
      <product>
      <category>Tile</category>
      <name>Angelic Peach</name>
      </product>
      <product>
      <category>Tile</category>
      <name>Cosmo</name>
      </product>
      <product>
      <category>Tile</category>
      <name>Durva</name>
      </product>
      <product>
      <category>Tile</category>
      <name>Isosilis</name>
      </product>
      <product>
      <category>Tile</category>
      <name>Magaloth</name>
      </product>
      <product>
      <category>Tile</category>
      <name>Trunklin</name>
      </product>
      <product>
      <category>Tile</category>
      <name>Googolfletch</name>
      </product>
      <product>
      <category>Tile</category>
      <name>Moskurbelf</name>
      </product>
      <product>
      <category>Tile</category>
      <name>DoChoaKoa</name>
      </product>

      ---products-component-for-use-in-main-application---
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300" creationComplete="this.productStream.send();">
      <mx:Script>
      <![CDATA[
      import mx.utils.ArrayUtil;
      import mx.utils.XMLUtil
      //var urlPath=" http://localhost/rogerwilko/AndeanStone/xml.asp";
      function xmlRequest():void {
      // Cancel all previous pending calls.
      productStream.cancel();
      var params:Object = new Object();
      params.func = 'products';
      productStream.send(params);
      }
      ]]>
      </mx:Script>
      <mx:HTTPService id="productStream"
      url=" http://localhost/rogerwilko/AndeanStone/xml.asp"/>

      <mx:Label text="Select A Product Category" top="0" left="0"/>

      <mx:ComboBox id="prodCatList" dataProvider="{mx.utils.ArrayUtil.toArray(this.productStream.lastResult.product)}" width="200" left="0" top="20" cornerRadius="3" fillAlphas="[0.5, 0.5]" themeColor="#00ff00" alpha="0.49">
      </mx:ComboBox>

      <mx:DataGrid id="prodList" dataProvider="{mx.utils.ArrayUtil.toArray(this.productStream.lastResult.product)}" columnWidth="200" width="200" left="0" top="55">
      <mx:columns>
      <mx:DataGridColumn headerText="{prodCatList.value}" dataField="name"/>
      </mx:columns>
      </mx:DataGrid>


      </mx:Canvas>


      Thanks in advance for any help you can provide me
      leo
        • 1. Re: Nested XML into comboBox
          ntsiii Level 3
          You will need to specify either a labelField or labelFunction. You can use a labelField if the value you want to show in the combo box is a first level property of the item.

          If the data you want to display is deeper in the item object, and you need to "dot down" to get it use a labelFunction.

          HTTPService resultFormat defaults to Object. I have never been comfortable about the way Flex converts xml into objects, so I always use e4x. This choice affects the structure of your item objects, and therefore the way you need to access the item objects properties.

          Try labelField, anif that doesn't work use a labelFunction. Note, you can debug the labelFunction quite handily.

          Tracy
          • 2. Re: Nested XML into comboBox
            leotemp Level 1
            Thanks for the reply Tracy, worked like a charm. I think one of the hardest things about being new to flex is understanding how much of the work is done for you. Once again thanks been trying to figure this out all day :P


            leo
            • 3. Re: Nested XML into comboBox
              ntsiii Level 3
              Another of the hardest things is deciding how long to bash your head against a wall before asking for help!

              Go on and ask. The worst that will happen is someone will snarl at you to read the docs, and you can get over that.

              One interesting effect: Post a question, and you figure out the answer yourself a few minutes later. Its like magic.

              Tracy