2 Replies Latest reply on Jan 19, 2007 4:06 AM by

    RemoteObject and arrayCollections

      I was working a little bit in flex and I came across an interesting question. I have a remoteobject that has a method called getAlbums. I have an optional argument of getAlbums, called authors. In the result handler I set whatever the result is to fullAlbumList ( an arrayCollection). I would like to be able to show all of the albums in one datagrid and only the albums of a given author in the other datagrid. The problem is I would call the same method for both of these and I would only set the full AlbumList arraycollection. Any ideas? Thanks.
        • 1. Re: RemoteObject and arrayCollections
          peterent Level 2
          So you have 1 dataset you want to show in two different places, just showing a subset of the data. Is that correct?

          [Bindable] var fullList:ArrayCollection;
          [Bindable] var authorList:ArrayCollection;

          Have your result handler do this:
          fullList = new ArrayCollection( event.result ); // or whatever you have
          authorList = new ArrayCollection( event.result ); // ditto

          Now you have 2 ArrayCollections using the same data source. If you look at fullList.source and authorList.source you will see that they are the same.

          Now add a filter to authorList to select the authors you want:

          var currentAuthor:String; // set this to the author you want to see
          function authorFilter( item:Object ) : Boolean
          return item.author == currentAuthor;

          // Now set the filter into the collection:
          authorList.filter = authorFilter; // set the function itself

          // Finally, tell the collection to refresh itself. You'll need to do this every time currentAuthor changes.

          The Collections are just views of the data. You can have many views of the same data. You can one view have a filter and the other a Sort.
          • 2. Re: RemoteObject and arrayCollections
            Thank you that answers my question.