Skip to main content
December 5, 2011
Answered

Filtrer array from callresponder in Ilist

  • December 5, 2011
  • 1 reply
  • 389 views

Hi

This is my first develop project so will be very glad for a little help

I have created an custom "class" called unit with 3 properties (name, uuid, type).

in my flex project i just make an service call to my wcf service to get all units (getAllUnits).

Then i bind the data to a list, and it all work.

My problem is i want to make an option to only show units with type "computer" or "user". (in this example there is no validating for users jet!)

i try to solved it with another service call (getOnlyComputers), but i can't bind my data to the list via an function, the list is empty. I think there must just be a way to filter my already existing servicecall (getAllUnits), but coud not found any information about it.

here are the relevant code:

[Bindable] public var cResponder:CallResponder = getListResult();

<s:List id="unitList" left="0" right="0" top="80" bottom="0" y="40"

            creationComplete="unitList_creationCompleteHandler(event)" change="unitList_changeHandler(event)">

        <s:AsyncListView list="{cResponder.lastResult}"/>

       

        <s:itemRenderer>

            <fx:Component>

                <s:IconItemRenderer labelField="" messageField="name" verticalAlign="middle"

                    iconFunction="getComputerIcon" iconWidth="32" iconHeight="32" >

                    <fx:Script>

                        <![CDATA[

                            import valueObjects.Unit;

                            private function getComputerIcon(item:Object):String

                            {

                                return "assets/Unit_" + item.unitType + "_48.png";

                            }

                        ]]>

                    </fx:Script>

                </s:IconItemRenderer>

            </fx:Component>

        </s:itemRenderer>

       

    </s:List>

public function getListResult():CallResponder

{

                if (activeBtn=="Computers") {

                    return getOnlyComputersResult;

                } else {

                    return getUnitsResult; }

            }

protected function unitList_creationCompleteHandler(event:FlexEvent):void

{

  if (activeBtn=="Computers") {

         getUnitsResult.token = cms.getOnlyComputers();

                } else {

         getUnitsResult.token = cms.getUnits();

             }

}

<fx:Declarations>

  <s:CallResponder id="getUnitsResult"/>

  <s:CallResponder id="getOnlyComputersResult"/>

</fx:Declarations>

This topic has been closed for replies.
Correct answer

Found a solution by my self

private function changeHandler(event:IndexChangeEvent):void {

if (event.newIndex==0) {
unitList.dataProvider = getOnlyComputersResult.lastResult;
} if (event.newIndex==1) {
unitList.dataProvider = getOnlyUsersResult.lastResult;
} else {
//unitList.dataProvider = getUnitsResult.lastResult;
}
}

1 reply

Correct answer
December 7, 2011

Found a solution by my self

private function changeHandler(event:IndexChangeEvent):void {

if (event.newIndex==0) {
unitList.dataProvider = getOnlyComputersResult.lastResult;
} if (event.newIndex==1) {
unitList.dataProvider = getOnlyUsersResult.lastResult;
} else {
//unitList.dataProvider = getUnitsResult.lastResult;
}
}