-1
我需要你幫忙找到一個解決方案來按創建日期時間排列數組。 我嘗試這個,但這個功能似乎只按日期排序,而不是按時間排在一起。as3按日期/時間順序目錄
private function triImgDate(folder:Array):void {
var acDirectory:ArrayCollection = new ArrayCollection();
for each (var tmp:File in folder) {
if (!tmp.isDirectory) {
if (tmp.extension != null && ArrayFunction.inArray(tabExt, tmp.extension.toLowerCase()))
{
listeImages.addItem(tmp);
}
}
else {
triImgDate(tmp.getDirectoryListing());
}
}
var dataSortField:SortField = new SortField();
dataSortField.name = "creationDate";
dataSortField.numeric = false;
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
listeImages.sort = numericDataSort;
listeImages.refresh();
}
所以,如果你能幫助我。
問候
//解決方案
private function triImgDate(folder:Array):void {
var acDirectory:ArrayCollection = new ArrayCollection();
var arTempListeImages:ArrayCollection = new ArrayCollection();
var arTempListeCompar:ArrayCollection = new ArrayCollection();
var objImg:Object;
for each (var tmp:File in folder) {
if (!tmp.isDirectory) {
if (tmp.extension != null && ArrayFunction.inArray(tabExt, tmp.extension.toLowerCase())) {
objImg= new Object();
//listeImages.addItem(tmp);
arTempListeImages.addItem(tmp);
objImg.creationDate=tmp.creationDate;
objImg.url=tmp.url;
objImg.pos=arTempListeCompar.length;
arTempListeCompar.addItem(objImg)
}
} else {
triImgDate(tmp.getDirectoryListing());
}
}
var dataSortField:SortField = new SortField();
dataSortField.name = "creationDate";
dataSortField.compareFunction = function (a:Object, b:Object) : int {
var na:Number = a.creationDate.getTime();
var nb:Number = b.creationDate.getTime();
if (na < nb)
return -1;
if (na > nb)
return 1;
return 0;
};
var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
arTempListeCompar.sort= numericDataSort;
arTempListeCompar.refresh();
var cpt:int=0;
for each (var objTem:Object in arTempListeCompar) {
listeImages.addItem(arTempListeImages[arTempListeCompar[cpt].pos]);
cpt++;
}
arTempListeImages=[];
arTempListeCompar=[];
acDirectory=[];
}
http://stackoverflow.com/questions/12398520/sort-arraycollection-by-date-then-time-flex – SushiHangover