我需要您帮助找到按创建日期时间排序数组的解决方案。 我试试这个,但这个功能似乎只按日期排序,而不是按时间排在一起。
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=[];
}
答案 0 :(得分:1)
你在这里要做的是用字符串表示比较twe个日期,这显然不是一个好方法。
您应该使用android:required="false"
对象的compareFunction
属性。这样的事情(未经测试):
SortField