3 Replies Latest reply on Jun 15, 2008 11:27 PM by bshashi

    Dynamically populating combo box

    bshashi
      Hi friends,

      I am new to flex.if any mistakes , I appologize. I want to dynamically populate combo box from database. I have used php on the backend. It returns the result in the associative array form.
      Actually the return value will be in the following form:

      name:hari id:1
      name:gita id:2

      The first one(label) is the name of the user and the second one(data) is their id. So what i want is to populate this int he form

      label:hari data:1
      label:gita data:2

      in the combo box. But I am unable to do it. My question is how do i create xml and populate those value into combo box? Thanks in advance.

      Shashi
        • 1. Re: Dynamically populating combo box
          Gregory Lafrance Level 6
          Its better if you can return XML from your PHP:

          <?xml version="1.0" encoding="utf-8"?>
          <items>
          <item name="hari" id="1"/>
          <item name="gita" id="2"/>
          </items>
          • 2. Re: Dynamically populating combo box
            ntsiii Level 3
            Yes, the list components cannot us an associative array (object) as a dataProvider. They must have a list of sime kind, like Array, XMLList, ArrayCollection or XMLListCollection.

            If you want to stay with the assoc array, you might be able to build an ArrayCollection by using a For Each loop.

            XML would be better though. Be sure to set resultFormat="e4x"

            Tracy

            Tracy
            • 3. Re: Dynamically populating combo box
              bshashi Level 1
              hi,


              Thanks for the help it worked. I did as follows:
              I created xml dynamically in the following format.
              users.xml

              <users><username data="1">abc</username>
              <username data="2">abc</username>
              <username data="3">abc</username>
              </users>

              data -> id of the user

              And populated it in the combobox as follows:
              <mx:ComboBox fontSize="10" id="comboPostINFStaff" dataProvider="{userRequestName.lastResult.users.username}" />

              Thanks once again

              Shashi