【问题标题】:Using filterFunction to do filtering based on more than 1 parameter使用 filterFunction 基于多个参数进行过滤
【发布时间】:2011-09-19 10:32:54
【问题描述】:

我定义了一个 XMLList,它从以下 XML 文件中获取数据:

    <modules>
        <module hab_id="1" module_id="1" default="true" access="true" />
        <module hab_id="1" module_id="2" default="true" access="true" />
        <module hab_id="1" module_id="2" default="true" access="false" />
        <module hab_id="1" module_id="2" default="false" access="true" />
        <module hab_id="2" module_id="3" default="true" access="true" />
        <module hab_id="2" module_id="3" default="false" access="true" />
    </modules>

现在在我的函数中,让我们在单击按钮时同时按 hab_id 和 module_id 进行过滤并填充数据网格。

我在函数中试过这个:

    public function click_Handler(event:MouseEvent):void{
        myXMLList.filterFunction = myFilter;
        myXMLList.refresh();
        myDatagrid.dataProvider = myXMLList;
    }

    private function myFilter(xml:XML):Boolean{
                    return Number(xml.@hab_id) == 1;
                    return Number(xml.@module_id) == 2;
                }

但过滤器似乎只适用于 hab_id。它不是同时按 hab_id 和 module_id 过滤的。

有什么帮助吗?

【问题讨论】:

    标签: xml actionscript-3 apache-flex flex4 filterfunction


    【解决方案1】:

    试试这个:

    private function myFilter(xml:XML):Boolean{
       return Number(xml.@hab_id) == 1 && Number(xml.@module_id) == 2;
    }
    

    您的第一次返回将从函数返回,绝不允许执行第二次返回。 将相等检查组合成一个返回值应该可以满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-21
      相关资源
      最近更新 更多