0
votes

I am using this filter function for my search bar. But it doesn't seems to be working.

The error that I am having is

Description Resource Path Location Type 1061: Call to a possibly undefined method refresh through a reference with static type spark.components:List. Malls.mxml /SGshopping/src/views line 15 Flex Problem

and

Description Resource Path Location Type 1119: Access of possibly undefined property filterFunction through a reference with static type spark.components:List. Malls.mxml /SGshopping/src/views line 14 Flex Problem

Sorry guys. I am still learning. This is really confusing and where did i do it wrongly?

 <?xml version="1.0" encoding="utf-8"?>

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 

        xmlns:s="library://ns.adobe.com/flex/spark" title="Malls"
        creationComplete="malls.send()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <s:HTTPService id="malls" url="assets/employees.xml" 
                       result="data=malls.lastResult.list.employee"/>
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            private function filterDemo():void{
                list.filterFunction=searchDemo;    - I am having errors here
                list.refresh();                     - and here
            }

            private function searchDemo(item:Object):Boolean{
                var isMatch:Boolean=false;
                if(item.name.toLowerCase().search(search.text.toLowerCase())!=-1){
                    isMatch=true;
                }
                return isMatch;
            }
        ]]>
    </fx:Script>

    <s:navigationContent/>
    <s:titleContent>
        <s:TextInput id="search" change="filterDemo()" x="10" y="10" prompt="Search"/>
    </s:titleContent>


    <s:List id="list" top="0" bottom="0" left="0" right="0"
            dataProvider="{data}"
            change="navigator.pushView(MallsDetails, list.selectedItem)">
        <s:itemRenderer>
            <fx:Component>
                <s:IconItemRenderer
                    label="{data.firstName} {data.lastName}"
                    messageField="title"/>
            </fx:Component>
        </s:itemRenderer>
    </s:List>


</s:View>
1

1 Answers

0
votes

Error Type 1061 and Type 1119 Above two error clear shows No filterFunction property and refresh method available in List Control it belongs to ListCollectionView Class So your case try to convert employee.xml to XMLListCollection.

Where data variable declared? Normally inside itemRenderer we can access data get and setter outside itemRenderer simply we can't access.

 <?xml version="1.0" encoding="utf-8"?>

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 

        xmlns:s="library://ns.adobe.com/flex/spark" title="Malls"
        creationComplete="malls.send()">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <s:HTTPService id="malls" url="assets/employees.xml" 
                       result="malls_resultHandler(event)"/>
    </fx:Declarations>

    <fx:Script>
        <![CDATA[

            [Bindable]
            private var employeeList:XMLListCollection; //instead data

            private function malls_resultHandler(event:ResultEvent):void
            {
                employeeList = new XMLListCollection(new XMLList(malls.lastResult.mallD));
            }

            private function filterDemo():void{
                employeeList.filterFunction=searchDemo;    //Here employeeList instead of list control 
                employeeList.refresh();                    //List control doesn't have filterFunction and refresh function.
            }

            private function searchDemo(item:Object):Boolean{
                var isMatch:Boolean=false;
                if(item.name.toLowerCase().search(search.text.toLowerCase())!=-1){
                    isMatch=true;
                }
                return isMatch;
            }
        ]]>
    </fx:Script>

    <s:navigationContent/>
    <s:titleContent>
        <s:TextInput id="search" change="filterDemo()" x="10" y="10" prompt="Search"/>
    </s:titleContent>


    <s:List id="list" top="0" bottom="0" left="0" right="0"
            dataProvider="{employeeList}"
            change="navigator.pushView(MallsDetails, list.selectedItem)">
        <s:itemRenderer>
            <fx:Component>
                <s:IconItemRenderer
                    label="{data.firstName} {data.lastName}"
                    messageField="title"/>
            </fx:Component>
        </s:itemRenderer>
    </s:List>


</s:View>

Based on your XML Struture:

var response:XML = malls.lastResult as XML;

var mallIDXMLList:XMLList = response.mallD;           

employeeList = new XMLListCollection(mallIDXMLList);