2017-02-28 80 views
-1

刪除重複值,這是我的ArrayCollection從ArrayCollection的在FLEX4

o = JSON.parse(event.result.toString()); 

jsonarray = new ArrayCollection(o as Array); 

這個數組中,我有產品名稱的重複值,所以我想刪除duplicacy。\ 我的代碼是在這裏,它不工作請讓我知道,我是一名flex初學者。 thanx提前。

function removeDuplicates(item:Object):Boolean 
{ 
    var returnValue:Boolean = false; 
    if (!myObject.hasOwnProperty(item.ProductName)) 
    { 
     myObject[item.ProductName] = item; 
     returnValue = true; 
    } 
    prodArray.push(myObject); 
    return returnValue; 
} 
+0

變種○:對象;請儘快回覆。其緊急 –

+0

[Flash as3可能的重複如何刪除數組中的重複?](http://stackoverflow.com/questions/5997822/flash-as3-how-do-i-remove-duplicates-in-an-陣列) – Clintm

回答

0

呼叫下方且在給出的filterCollection方法使用的filterFunction刪除重複

private var tempObj:Object = {}; 

private function filterCollection():void { 
    // assign the filter function 
    jsonarray.filterFunction = removeDuplicates; 
    //refresh the collection 
    jsonarray.refresh(); 
} 

private function removeDuplicates(item:Object):Boolean { 
    return (tempObj.hasOwnProperty(item.ProductName) ? false : tempObj[item.ProductName] = item && true); 
}