For example, say I have:
public var usersOnlineArray:Array = new Array(bob,jim,tim,marry,luke);
and when I put that into my datagrid like this:
buddylist.dataProv开发者_JAVA技巧ider = new DataProvider(usersOnlineArray);
buddylist.rowCount = buddylist.length;
bldBuddyList(buddylist);
How could I, let's say, prevent luke from appearing in the datagrid? Basically make him not appear but technically "still be there" so I can make him reappear later but?
I'd start by using ArrayCollection rather than Array since you can make use of data binding this way.
ArrayCollection also has a filterFunction
property that will allow you to hide things but still keep them in the collection. The docs will expand on all of this but the gist is:
Make the ArrayCollection, it just takes plain ole Array in the constructor.
public var usersArr:Array = [bob, jim, tim, marry, luke];
public var usersAC:ArrayCollection = new ArrayCollection(usersArr);
Set the AC to be the data provider for the List.
buddyList.dataProvider = usersAC;
Define the filter function. This function takes an object and returns true if it should be visible, false if not.
public function myFilterFunction(o:Object):Boolean
{
if (o.toString() == "luke") return false;
return true;
}
Then apply this function to the AC.
usersAC.filterFunction = myFilterFunction;
To remove the filter simply null our the filterFunction property.
usersAC.filterFunction = null;
If you stick the array in an ArrayCollection, you can add a filter function it to. The underlying data is un-affected.
精彩评论