2 Replies Latest reply on May 7, 2010 8:00 AM by EricJ32

    Different "views" of the same ArrayCollection

    EricJ32 Level 1



      How would be the best way of achieving this?


      I'll simpify the problem, so this is fairly ficticious...


      Let's say I have a class, Student:


      public class Student


           public var name:String;

           public var isActive:Boolean;

           public var averageGrade:int; // 0 = A, 1 = B, 2 = C, 3 = D (or whatever)

           public var likesCabbage:Boolean;



      I have an ArrayCollection of all the students in my school, called allStudents.


      I now want to display, on one screen, several views of this ArrayCollection:


      1. All Students (ie unfiltered)

      2. Students where isActive = true;

      3. Students with an average grade of B or above

      4. Students that like cabbage.


      Obviously, if I simply apply a filter to the ArrayCollection, it will impact on all of these views. So I basically need a filter that is limited to each component.


      I could copy the ArrayCollection four times (looping through the original and using addItem() to add each item to the new collections, so they aren't linked) and apply a filter to each new collection, but this seems messy - and among other problems, the new ArrayCollections won't be bound to the original, so if that changes, the others won't be automatically updated.


      Is there a best practice for this situation?