【问题标题】:Filtering data from XML从 XML 中过滤数据
【发布时间】:2014-02-16 12:27:34
【问题描述】:

我正在为我的搜索栏使用这个过滤器功能。但这似乎不起作用。

我遇到的错误是

描述资源路径位置类型 1061:通过静态类型 spark.components:List 的引用调用可能未定义的方法刷新。 Malls.mxml /SGshopping/src/views 第 15 行 Flex 问题

描述资源路径位置类型 1119:通过静态类型 spark.components:List 的引用访问可能未定义的属性 filterFunction。 Malls.mxml /SGshopping/src/views 第 14 行 Flex 问题

对不起各位。我仍在学习。这真的很令人困惑,我在哪里做错了?

 <?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>

【问题讨论】:

标签: xml actionscript-3 apache-flex flex4.5


【解决方案1】:

错误类型 1061 和类型 1119 以上两个错误清除显示列表控件中没有可用的 filterFunction 属性和刷新方法它属于 ListCollectionView 类所以你的案例尝试将employee.xml 转换为 XMLListCollection。

数据变量在哪里声明?通常在 itemRenderer 内部,我们可以访问 itemRenderer 外部的数据获取和设置,只是我们无法访问。

 <?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>

基于您的 XML 结构:

var response:XML = malls.lastResult as XML;

var mallIDXMLList:XMLList = response.mallD;           

employeeList = new XMLListCollection(mallIDXMLList);

【讨论】:

  • 谢谢。但是现在列表中没有数据。
  • 显示您的 XML 结构
  • 1Ion Orchard
    2 Orchard Turn
    Singapore 238801+65 6238 8228customercare@ionorchard.com.sgIon.png
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多