1 Reply Latest reply on Oct 26, 2009 7:59 AM by Kurt Mossman

    Comparing Two Arrays

    MrFork

      Hello All, I'm trying to compare two arrays with each other and replacing the contents of one with another where they are the same. This sounds very simple but Im having some difficulty. Im using the function 'setItemAt' to replace the item. As the function requires an index, which is 'i' in the code below but I don't want it to be 'i' - I want the index to be a field in the sql array called 'pageviews'

       

      So the code should be something like " sql.setItemAt(gdata[_i].pageviews,sql[i].pageviews); " but this obviously doesn't work. How do I get flex to actually replace a field instead of the whole row?

       

      Thanks


      Craig

       

       

      public function mergeRemClick(sql:ArrayCollection,gdata:ArrayCollection):void
              {
                  for (var i:int = 0; i<sql.length; i++)
                      {
                          for (var _i:int = 0; _i<gdata.length; _i++)
                          {
                              if (sql[i].link == gdata[_i].pagepath)
                              {
                                 sql.setItemAt({pagepath:gdata[_i].pageviews}i); << ------------------------- ISSUE LINE
                              } 
                          }
                      }
                      sql.refresh();
              }

        • 1. Re: Comparing Two Arrays
          Kurt Mossman Adobe Employee

          Try this... it will get the sql item at the index then you just need to update the pagepath field with the gdata value and use itemUpdated to notify the collection that you modified the value... it would then update in your dataProvider.

           

                            for (var i:int = 0; i<sql.length; i++)
                              {
                                  for (var _i:int = 0; _i<gdata.length; _i++)
                                  {
                                      if (sql[i].link == gdata[_i].pagepath)
                                      {
                                          sql.getItemAt(i).pagepath=gdata[_i].pageviews;
                                          sql.itemUpdated(sql.getItemAt(i));
                                      }
                                  }
                              }

           

          -Kurt.