Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ItemRender data change

I have a List with an ItemRenderer. When I click a button, then a property of the ArrayCollection I bound to the list is changed.

When I click the button, then it does change the property, but the list doesn't change.

How do I solve this.

Here's my code

<fx:Script>
    <![CDATA[

        [Bindable] 
        public var controllers:ControllerCollection = new ControllerCollection();

        private function hideTheFirstItem(evt:MouseEvent):void
        {
            (controllers[0] as Controller).meetsRequirements = false;

                    //these methods don't work unfortunatly
                    controllers.itemUpdated(controllers[0]);
                    controllers.refresh();

        }


    ]]>
</fx:Script>

<mx:List id="listControllers" dataProvider="{controllers}">
    <mx:itemRenderer>
        <fx:Component>
            <solutionItems:displaySolutionItem visible="{data.meetsRequirements}" />
        </fx:Component>
    </mx:itemRenderer>
</mx:List>
<mx:Button label="test" click="hideTheFirstItem(event)" />

(ControllerCollection extends ArrayCollection)

Thanks!

Vincent

like image 944
Vinzcent Avatar asked Aug 27 '26 06:08

Vinzcent


2 Answers

Two ways:

  1. collection.refresh()
  2. collection.itemUpdated()

Of course, ControllerCollection is not a standard Flex Collection class; so I am just assuming that it implements the ICollectionView interface.


Update: I do notice that your code is set to modify the first element of the ArrayCollection

private function hideTheFirstItem(evt:MouseEvent):void
{
 (controllers[0] as Controller).meetsRequirements = false;

 //these methods don't work unfortunatly
 controllers.itemUpdated(controllers[0]);
 controllers.refresh();
}

I wanted to be sure to specify that the first element of the collection may not be the first element currently visible in the view. I wonder if that is causing you issues.

like image 178
JeffryHouser Avatar answered Aug 30 '26 10:08

JeffryHouser


Without seeing your item renderer, I need to make some assumptions.

First, I will assume that your item renderer is using data binding to the meetsRequirements property. If that is the case, then the meetsRequirements property needs to notify when that property changes. If you add the [Bindable] tag to that property or the Controller class, then the meetsRequirements property will notify the itemRenderer to update that field based on your data binding.

If my assumptions are wrong, we need to see the code to give you any further thoughts.

like image 37
Brian Genisio Avatar answered Aug 30 '26 10:08

Brian Genisio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!