2 Replies Latest reply on Feb 21, 2011 8:46 PM by BhaskerChari

    Probleam with ArrayCollection

    dm1410
      Hey Guys.
      I have a code here that do a search on my database in php that generates a xml where this xml is read on flex. With the php and the xml is everything works well. My probleam is: If I have more than one register returning of my search this code works very well without any probleam. But is this search returning just one register don't appear nothing in my datagrid. Follow the code that I am using if anyone knows why this have a probleam with one register please help me. ANd sorry about my english. Thanks guys

      FLEX:
      <mx:VBox label="Arquivos Disponíveis" click="mudaAba(1)" width="100%" height="100%">
      <mx:DataGrid width="100%" dataProvider="{datalist}" id="dg" itemClick="baixarArquivo(event)">
      <mx:columns>
      <mx:DataGridColumn headerText="Arquivos" dataField="nome"/>
      <mx:DataGridColumn headerText="Tipo do Arquivo" dataField="tipo"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:VBox>

       

      AS:

       

      [Bindable]
      public var datalist:ArrayCollection;

       

      private function respostaArquivos(event:ResultEvent):void{
      //Alert.show(""+event.result.data.row.cliente+"");
      datalist = event.result.data.row;
      Alert.show(""+datalist[0].cliente+"");
      var rowcount:String = event.result.data.num;
      }
        • 1. Re: Probleam with ArrayCollection
          saisri2k2 Level 4

          check the XML that is comming over, is it the same one for both the single as well as the multiple registers? debug in the result handler to see what you have in the arraylist at the end of the method, try using traces/debug points.

          • 2. Re: Probleam with ArrayCollection
            BhaskerChari Level 4

            Hi dm,

             

            The problem here occurs with the one record is event.result.data.row is not an ArrayCollection when you have a single register/record.

            So you need to have a check for this in your code..as shown below:

             

            private function respostaArquivos(event:ResultEvent):void{
            //Alert.show(""+event.result.data.row.cliente+"");

            if(event.result.data.row is ArrayCollection)
                 datalist = event.result.data.row;

            else if(event.result.data.row is Object)

            {

                 datalist = new ArrayCollection();

                 datalist.addItem(event.result.data.row);

            }   
            Alert.show(""+datalist[0].cliente+"");
            var rowcount:String = event.result.data.num;
            }

             

            Thanks,

            Bhasker Chari