I have a situation where I have a List showing a queue of Upload Objects:
public class Upload
{
public var type:String; // Update or Create
public var title:String;
public var message:String;
...
}
So, the list dataprovider would look something like:
var arrayCol:ArrayCollection = new ArrayCollection(
{new Upload("Upload", "blah"),
new Upload("Create", "blah2")});
list.dataProvider = arrayCol;
I would like to create three different views of the List:
- One showing All uploads in the queue
- Another showing only the Upload items with
Upload.type == "Update"
- and another showing only the items with
Upload.type == "Create"
.
Another example of this would be on an email inbox, where we could filter "All, unread, or read".
I realise I could just create three different lists, one for each view of the list (maybe I'm just being picky) but I was wondering:
Is there is any easy way to conditionally select the items to display from a DataProvider based on a parameter (for example type =="Upload"
) so I don't have to juggle three separate ArrayCollections about?
If not, 3 different lists and 3 ArrayCollections it is!
You want to look at the filter function property on Array Collection. You can assign the filter to a function that will look at a property on upload, and conditionally decide if it should be included in the collection. With a filter function set, and refresh() called on the collection, a subset of objects will appear to be in the ArrayCollection, but the originals are not lost. Simply clearing the filter then calling refresh() on the ArrayCollection will return it to its original collection.
var arrayCol:ArrayCollection = new ArrayCollection(
{new Upload("Upload", "blah"),
new Upload("Create", "blah2")});
arrayCol.filterFunction = filterCompleted;
arrayCol.refresh();
Then your filter function will look something like:
private function filterCompleted(item:Object):Boolean{
if(Upload(item).isComplete)
return true;
return false;
}
Why not to switch and apply different ArrayCollection
's filterFunction
s according to the documentation?
精彩评论