4 Replies Latest reply on Jan 27, 2010 3:32 AM by 435.mahesh

    problem in arraycollection?

    435.mahesh

      Hi,

      I given an arraycollection as a dataprovider to a datagrid which was with some itemrenderers.
      while retrieving the saved data from the grid i am copying some columns like
      arraycoll[3]['name'] = 'saome name';
      when i am assigning some value to a particular row item in the dataprovider arraycollection,
      all the rows are updating with the same name.
      for example: if an arraycollection has 3 items like
      arrcoll:ArrayCollection = new Arraycollection([
      {name:'sample1' id:1},
      {name:'sample2' id:1},
      {name:'sample3' id:1}
      ]);
      when i want to update the second name i.e.sample2 with sample4 and i assigned that value like
      arrcoll[1]['name']='sample4';
      all the items are effecting like

       

      {name:'sample4' id:1},
      {name:'sample4' id:1},
      {name:'sample4' id:1}

       

      So how can i update a single item in an arraycollection.
      please provide me the solution

       

      Regards

      D.Mahesh Babu

        • 1. Re: problem in arraycollection?
          archemedia Level 4

          the line

           

          arrcoll[1]['name']='sample4';

           

          is correct

           

          so there's something else going on.

           

          Can you elaborate on:

           

          ...while retrieving the saved data from the grid i am copying some columns like
          arraycoll[3]['name'] = 'saome name';...

           

          Can you post an example?

           

          Dany

          • 2. Re: problem in arraycollection?
            435.mahesh Level 1

            Here i am populating an arraycollection with the data which is coming from the database.

            In this arraycollection i want to copy some items into the other arraycollection which is a dataprovider

            to a datagrid.(I dont want to copy the complete row, but some items in a row)

             

            so when i am copying like

            for(var i:int=0;i<arrcoll2.length;i++)

            {

                 arrcoll[i]['name']=arrcoll2[i]['name'];

            }

            So the problem is after the above loop was completed, all the rows in the arrcoll is filled with

            the last row items of arrcoll2.

             

            Another problem is in the datagrid i used an itemrenderer of richtexteditor to edit that cell.

            so when i edit that cell and save the edited data to the dataprovider like

            data[listData.dataField] = 'editedCellData';

            all the cells of that column are updated with the same data.

             

            So please provide me the solution. If u want anymore details please reply me soon.

            Thanks

            • 3. Re: problem in arraycollection?
              archemedia Level 4

              Probably, the problem here is that you copy references from one arrayCollection to the other one, so when you change a property of an object in the first one, the other one will reflect that change too. Is there any line in your code which says something like arrcoll = arrcoll2?

              Solving this problem will likely solve your second problem automatically.

               

              If not, please try to post your (simplified) code.

               

              Dany

              • 4. Re: problem in arraycollection?
                435.mahesh Level 1

                Thanks dany my problem solved