Modifying ItemRender Data

I have a list with ItemRenderer. When I click the button, then the ArrayCollection property associated with the list changes.

When I click the button, it changes the property, but the list does not change.

How to solve it.

Here is 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)

Thank!

Vincent

+3
source share
4 answers

First, do not try to create new collections if you do not need it.

I believe your problem lies in this statement: (controllers[0] as Controller).meetsRequirements = false;which should fail at compilation, because the collection item cannot be obtained using the square bracket annotation. You need to use the function getItemAt(index:int).

, false , "" , . , :

<s:Application creationComplete="onCreationComplete()">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable] public var data:ArrayCollection = new ArrayCollection();

            private function onCreationComplete():void
            {
                // TODO: need to add data here
                // Adding filter function
                data.filterFunction = filterItems;
            }

            private function filterItems(item:Object):Boolean
            {
                return item.meetsRequirements;
            }

            private function hideFirstItem():void
            {
                if(data.length > 0)
                {
                    Controller(data.getItemAt(0)).meetsRequirements = false;
                }

                data.refresh();
            }
        ]]>
    </fx:Script>

    <mx:List id="listControllers" dataProvider="{data}" />
    <mx:Button label="test" click="hideFirstItem()" />
</s:Application>

. , .

+1

:

, ControllerCollection Flex Collection; , ICollectionView.


: , 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();
}

, , . , .

+2

, .

First, I assume the item renderer uses data binding to the property meetsRequirements. If so, then the property meetsRequirementsshould notify when this property changes. If you add a tag [Bindable]to this property or class Controller, the property meetsRequirementswill notify itemRenderer about updating this field based on data binding.

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

+2
source

Try the following:

<fx:Script>
    <![CDATA[

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

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

            dispatchEvent(new Event("refreshMyList"));
        }


    ]]>
</fx:Script>
+1
source

All Articles