This is some code I have written for a similar project... It simply runs 
through the dataProvider searching for a matched id. If it finds the id, then 
it replaces the row, otherwise it adds a new row at the end of the 
dataProvider. Since you want to track add, update and delete, you'll probably 
need to specify another field that is returned with the data, such as 
_row_status (0=new,1=updated,2=deleted), and modify the script likewise.



public var dataProvider:ArrayCollection = new ArrayCollection();

public function onUpdateData(result:Array):void
{
 var i:Number, j:Number, row:Object, item:Object, id:Number, found:Boolean;
 for (i=0;i<result.length;i++){
  row = result[i];
  id = row.id;
  
  found = false;
  for (j=0;j<dataProvider.length;j++){
   item = dataProvider.getItemAt(j);
   if (item.id == id){
    dataProvider.setItemAt(row,j);
    found = true;
    break;
   }
  }
  
  if (!found){
   dataProvider.addItem(row);
  }
  
 }
 
 dataProvider.refresh();

}



Any questions, just ask.

Cheers,
Adam

  ----- Original Message ----- 
  From: oneproofdk 
  To: flexcoders@yahoogroups.com 
  Sent: Wednesday, February 07, 2007 11:10 PM
  Subject: [flexcoders] Re: Poor man's PUSH technology (aka reload data using 
timer)


  Hi Adam.

  Thanks for your reply - I like your idea about keeping the "pushed"
  data to a minimum. My original idea was to get the entire dataset and
  then loop through it and compare - your idea is way better.

  I'm really in need of some examples of a timer function, and perhaps
  some code to make the comparing of data. Anyone that can help me out
  there ?

  Thanks again,
  Mark

  --- In flexcoders@yahoogroups.com, "Adam Royle" <[EMAIL PROTECTED]> wrote:
  >
  > Hi Mark,
  [snip]



   

Reply via email to