0

我正在紧急寻找一种解决方案,以从 Flex 中的数组中删除所有重复项。我需要过滤掉过滤数据数组中的所有重复项。

indexOf 在这里不起作用,我相信是因为对象被加载到数组中。

提前致谢

var columnArray:Array = ['ingenre']; //Datagrid column names to filter on
            var songArray:Array = ['id']; //Datagrid column names to filter on
            var gridDataProvider:ArrayCollection = PhotoData; //Name of datagrid's dataprovider. In this case e.g. databases
            var dataGridName:String = 'dgUserRequest'; //Name of the datagrid you are filtering by
             
            //Do not edit code past this point
            var filteredData:Array = [];
            var added:Boolean=false;
            var i:int;
            var j:int;

            var filtertxt: String;
            var matchtxt:String;
             
            // Loop Through Grid
            for(i=0; i < gridDataProvider.length; i++){

                added = false;
                 
                //Loop through grid column
                for(j=0; j<columnArray.length; j++){

                    if(gridDataProvider[i][columnArray[j]]!=null){

                        //Grab datagrid cell contents, trim it, and convert to lowercase for comparison.
                        var filterString:String = gridDataProvider[i][columnArray[j]].toString().toLowerCase();
                        var songIdString:String = gridDataProvider[i][songArray[j]].toString().toLowerCase();

                        //Compare the datagrid string(filterString) to the user typed string(filterText).
                        if(!added){

                            // loop through the Array & check if there is a match. 
                            for (var k:int = 0;k < filterText.length; k++)
                            {

                                filtertxt = filterString.toLowerCase();
                                matchtxt = filterText[k].toLowerCase();

                                //if(filterString.toLowerCase() == filterText[k].toLowerCase()){

                                if(filtertxt.search(matchtxt) >= 0){

                                    if (cmd_classic.selected == true)
                                    {
                                        trace(filteredData.indexOf(songIdString));
                                        if(filteredData.indexOf(songIdString) < 0)
                                        {
                                            if ((filtertxt.search("class") == -1) && (filtertxt.search("baroque") == -1))
                                            {
                                                if (filteredData.indexOf(songIdString) == -1)
                                                {
                                                    filteredData.push(gridDataProvider[i]);
                                                    added = true;
                                                }
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {

                                        if (filteredData.lastIndexOf(songIdString) <= 0)
                                        {
                                            filteredData.push(gridDataProvider[i]);
                                            added = true;
                                        }

                                    }
                                }   
                            }
                        }else{
                            //Do nothing, break out.
                            break;
                        }
                    }
                }
            }
4

1 回答 1

0

Flex 并没有我所知道的 Set 类。但是,当我需要从列表中获取唯一值列表时,我过去所做的是创建一个新的字典。使用我想要重复数据删除的值作为键遍历列表,并在完成后获取键集。

于 2013-10-08T20:35:09.983 回答