2 Replies Latest reply on Apr 6, 2011 12:15 PM by miguel8312

    split the arraycollection based on value

    miguel8312 Level 3

      hi guys I'm hoping to get an idea on how to do this efficiently. I have an arraycollection whish is getting populated from a webservice. I would like to test one field in the array collection for either positive or negative. When its negative i want to add it to a different field of the addarraycollection any ideas

      here is what i have so far.

       

       

                                  
                  private function GetGrantDetailResult(event:ResultEvent):void
                  {
                  
                  for each(var item:Object in event.result as ArrayCollection)    
                  {
                      GrantDetailArray.addItem({"fgbtrnd_doc_code":       item.fgbtrnd_doc_code,
                                                "fgbtrnd_Activity_date":  item.fgbtrnd_Activity_date,
                                                "fgbtrnd_acct_Code":        item.fgbtrnd_acct_Code,
                                                "fgbtrnd_trans_desc":        item.fgbtrnd_trans_desc,
                                                "fgbtrnd_trans_amt":        item.fgbtrnd_trans_amt,
                                                "total"    :                item.total 
                                                  })
                      
                      
                      
                  }    
                      
                      
                  GrantsDetailGrid.dataProvider = GrantDetailArray;
                      
                  }
      

      what i like to do is like put a conditional statement within the add item method to essestially add the negative to say "fgbtrnd_trans_neg_amt""

       

      any ideas suggestion would be greatly appreciated.

      Miguel

        • 1. Re: split the arraycollection based on value
          miguel8312 Level 3

          phsudo code

          of what i like to do.

           

           

                         for each(var item:Object in event.result as ArrayCollection)    
                      {
                          GrantDetailArray.addItem({"fgbtrnd_doc_code":       item.fgbtrnd_doc_code,
                                                    "fgbtrnd_Activity_date":  item.fgbtrnd_Activity_date,
                                                    "fgbtrnd_acct_Code":        item.fgbtrnd_acct_Code,
                                                    "fgbtrnd_trans_desc":        item.fgbtrnd_trans_desc,
                                                    if(item.fgbtrnd_trans_amt > 0){"fgbtrnd_trans_amt":item.fgbtrnd_trans_amt,}
                                                    else {"fgbtrnd_trans_neg_amt":        item.fgbtrnd_trans_amt},
                                                     "total"    :                item.total 
                                                      })
          
          • 2. Re: split the arraycollection based on value
            miguel8312 Level 3

            i found the answer via another thought.

            for each(var item:Object in event.result as ArrayCollection)    
                        {
                            
                        if (item.fgbtrnd_trans_amt > 0)    
                            
                        {
                            
                            GrantDetailArray.addItem({"fgbtrnd_doc_code":            item.fgbtrnd_doc_code,
                                                      "fgbtrnd_Activity_date":  item.fgbtrnd_Activity_date,
                                                      "fgbtrnd_acct_Code":        item.fgbtrnd_acct_Code,
                                                      "fgbtrnd_trans_desc":        item.fgbtrnd_trans_desc,
                                                      "fgbtrnd_trans_amt":        item.fgbtrnd_trans_amt,
                                                      "total"    :                item.total 
                                                        })
                        }    
                        
                        
                        
                        if(item.fgbtrnd_trans_amt < 0)
                        
                            GrantDetailArray.addItem({"fgbtrnd_doc_code":      item.fgbtrnd_doc_code,
                                                  "fgbtrnd_Activity_date":     item.fgbtrnd_Activity_date,
                                                  "fgbtrnd_acct_Code":           item.fgbtrnd_acct_Code,
                                                  "fgbtrnd_trans_desc":           item.fgbtrnd_trans_desc,
                                                  "fgbtrnd_trans_neg_amt":       item.fgbtrnd_trans_amt,
                                                  "total"    :                   item.total 
                            })
                            
                        }    
                            
                            
                        GrantsDetailGrid.dataProvider = GrantDetailArray;
                            
                        }