检查对象并返回是否找到该元素

时间:2015-10-22 16:59:41

标签: flex actionscript flash-builder

我试图为在Object中找到的项返回true,尽管对象中的某些数组中有多个元素。例如,selectedEventTypes [9]有一个[canceled,cancelled2,cancelled3]数组,虽然只要item.eventType被取消,它就永远不会意识到它在Object中并且总是为此返回false。

private function eventFilterFucntion(item:Object):Boolean
{   
    if(selectedEventTypes.indexOf(item.eventType)>-1)
    {
        return true;
    }
    return false;
}

1 个答案:

答案 0 :(得分:0)

您似乎已将 selectedEventTypes 定义为数组数组,如:

size

其中

private var selectedEventTypes:Array = [["A1", "A2"],
        ["B1","B2"],
        ["C1","C2"],
        ["D1","D2"],
        ["E1","E2"],
        ["F1","F2"],
        ["G1","G2"],
        ["H1","H2"],
        ["I1","I2"],
        ["Cancelled", "Cancelled2", "Cancelled3"],
        ["Received","Last"]];

在这种情况下,您可以更改 eventFilterFunction ,如下所示:

selectedEventTypes[9] = ["Cancelled", "Cancelled2", "Cancelled3"]

试试这个示例应用程序:

private function eventFilterFucntion(item:Object):Boolean
    {
        for each(var eachArray:Array in selectedEventTypes)
        {
            if(eachArray.indexOf(item.eventType) > -1)
            {
                return true;
            }
        }
        return false;
    }