3 Replies Latest reply on Sep 24, 2008 11:22 AM by ntsiii

    Merging 2 datasources at Array level

    eexposito
      I am trying to merge 2 data sources into 1 to be used as a data provider for an AdvancedDataGrid:

      Originally I have this for a single data source:

      var dsrc:Array = new Array();
      dsrc.push({col1:val1,col2:val2});
      dsrc.push({col1:val3,col2:val4});

      Now I have a second data source that I am trying to merge. So I want the final array to look like this:

      var dsrc:Array = new Array();
      dsrc.push({col1:val1,col2:val2, col3:val5, col4:val6});
      dsrc.push({col1:val3,col2:val4, col3:val7, col4:val8});

      I tried doing this ... it compiles but it doesn't work as expected:

      var dsrc:Array = new Array();

      var temp1:Array = new Array();
      temp1.push({col1:val1});
      temp1.push({col2:val2});
      temp1.push({col3:val5});
      temp1.push({col4:val6});

      dsrc.push(temp1);

      var temp2:Array = new Array();
      temp2.push({col1:val3});
      temp2.push({col2:val4});
      temp2.push({col3:val7});
      temp2.push({col4:val8});

      dsrc.push(temp2);

      Is there a proper way to merge these two?

      Thanks,
      EE
        • 1. Re: Merging 2 datasources at Array level
          ANewFlexUser
          var dsrc:Array Collection= new ArrayCollection;

          var temp1:Array = new Array();
          temp1.push({col1:val1});
          temp1.push({col2:val2});
          temp1.push({col3:val5});
          temp1.push({col4:val6});

          dsrc.addItem(temp1);

          var temp2:Array = new Array();
          temp2.push({col1:val3});
          temp2.push({col2:val4});
          temp2.push({col3:val7});
          temp2.push({col4:val8});

          dsrc.addItem(temp2);
          • 2. Re: Merging 2 datasources at Array level
            eexposito Level 1
            Tried that but it didn't work ...
            • 3. Re: Merging 2 datasources at Array level
              ntsiii Level 3
              I think you are confusing Array with Object(associative array)
              This is an object with two properties:
              {col1:val1,col2:val2}
              This is an object with 4 properties
              {col1:val1,col2:val2, col3:val5, col4:val6}

              This makes a 2 element Array of the 4 property Objects:
              dsrc.push({col1:val1,col2:val2, col3:val5, col4:val6});
              dsrc.push({col1:val3,col2:val4, col3:val7, col4:val8});

              So what are your two data sources? Are you combining two Arrays, where each element is a 4 property object?

              Or are you combining an array of 2 property objects with a different array of 2 property objects, and wanting to get an array of 4 property objects?

              So instead of showing how you think you need to build the two source arrays, show us what they are.

              Tracy