ArrayCollection
è una sottoclasse di ListCollectionView
che ha un sort
property. La classe Sort
ha un compareFunction
property che è possibile utilizzare per definire le funzioni di ordinamento personalizzate.
private function sortFunction(a:Object, b:Object, array:Array = null):int
{
//assuming that 'level' is the name of the variable in each object
//that holds values like "Critical", "High" etc
var levels:Array = ["Low", "Medium", "High", "Critical"];
var aLevel:Number = levels.indexOf(a.level);
var bLevel:Number = levels.indexOf(b.level);
if(aLevel == -1 || bLevel == -1)
throw new Error("Invalid value for criticality ");
if(aLevel == bLevel)
return 0;
if(aLevel > bLevel)
return 1;
return -1;
}
var sort:Sort = new Sort();
sort.compareFunction = sortFunction;
arrayCollection.sort = sort;
arrayCollection.refresh();
Funziona bene amar grazie – skumarvarma
funzione dovrebbe restituire int – zinovii
@zdmytriv fissi; Grazie :) – Amarghosh