Hi all, I've been having weird problems involving Lists, dataProviders, 
ListCollectionViews with  and ArrayCollections.  I was able to reproduce one of 
my problems below.

I have a ListCollectionView (filtered_stuff) that's viewing an ArrayCollection 
(stuff).  stuff initially just has one element.  filtered_stuff has a 
filterFunction that filters out this element.

Here's the weird part.  Clicking on Add item once does not show the added item 
in the List.  Clicking on Add item again will result in TWO items showing up in 
the list.  After that, clicking Add item behaves as you might expect.

Why is it behaving this way?

Thanks,

Ben

Code:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
    <mx:Panel title="List dataProvider test" creationComplete="onCreate()" 
        paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">

        <mx:List id="list" width="100%" dataProvider="{filtered_stuff}"/>
        <mx:Button click="addItem()" label="Add item"/>
    </mx:Panel>

    <mx:Script>
<![CDATA[
import mx.collections.ListCollectionView;
import mx.collections.ArrayCollection;

[Bindable] public var stuff:ArrayCollection;
[Bindable] public var filtered_stuff:ListCollectionView;

public function addItem():void {
    trace("adding item", stuff.length);
    stuff.addItem({label: stuff.length});
}

public function onCreate():void {
    stuff = new ArrayCollection([{label: 0}]);
    filtered_stuff = new ListCollectionView(stuff);
    filtered_stuff.filterFunction = function(item:Object):Boolean {
        return item.label > 0;
    }
    filtered_stuff.refresh();
}
]]>
    </mx:Script>
</mx:Application>


Reply via email to