我正在紧急寻找一种解决方案,以从 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;
}
}
}
}