ArrayCollection的排序,然后按日期和时间 - 的Flex [英] sort ArrayCollection by date then time - Flex
本文介绍了ArrayCollection的排序,然后按日期和时间 - 的Flex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我想用日期,然后时间整理一个ArrayCollection(如果有两个项目具有相同的日期)。我把它按日期罚款(年/月/日)的排序,但我想不通的时间位,时间为24小时格式因此code将是基本相同的日期。
这是在code我用日期排序,它工作正常。
进口mx.collections.SortField;
进口mx.collections.Sort;
私有函数的sort():无效
{
VAR dataSortField:=的SortField新的SortField();
dataSortField.name =日期;
VAR arrayDataSort:分类=新的排序();
arrayDataSort.fields = [dataSortField]
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
解决方案
您可以使用此code按日期和时间排序:
私有函数的sort():无效
{
VAR dataSortField:=的SortField新的SortField();
dataSortField.name =日期;
dataSortField.compareFunction =功能(A:对象,B:对象):INT {
变种NA:数= a.date.getTime();
VAR注:数= b.date.getTime();
如果(的Na; NB)
返回-1;
如果(NA> NB)
返回1;
返回0;
};
VAR arrayDataSort:分类=新的排序();
arrayDataSort.fields = [dataSortField]
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
I have an ArrayCollection that I'd like to sort by date and then time (in case there's two items with the same date). I've got it sorting by date fine (YYYY/MM/DD) but I can't figure out the time bit, time is in 24 hour format so the code would be basically the same as for the date.
This is the code I used for the date sorting, it works fine.
import mx.collections.SortField;
import mx.collections.Sort;
private function sort():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "date";
var arrayDataSort:Sort = new Sort();
arrayDataSort.fields = [dataSortField];
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
解决方案
You can use this code to sort by date and time:
private function sort():void
{
var dataSortField:SortField = new SortField();
dataSortField.name = "date";
dataSortField.compareFunction = function (a:Object, b:Object) : int {
var na:Number = a.date.getTime();
var nb:Number = b.date.getTime();
if (na < nb)
return -1;
if (na > nb)
return 1;
return 0;
};
var arrayDataSort:Sort = new Sort();
arrayDataSort.fields = [dataSortField];
reminderXMLArray.sort = arrayDataSort;
reminderXMLArray.refresh();
}
这篇关于ArrayCollection的排序,然后按日期和时间 - 的Flex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文