本文介绍了动作:ArrayCollection的排序按日期:YYYY-MM-DD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象的ArrayCollection。每个对象都具有以下键/值:
{日期:2009-12-01,参观= 13555,bouceRate = 45}
{日期:2009-12-05,参观= 46955,bouceRate = 45}
{日期:2009-12-06,参观= 13685,bouceRate = 45}
{日期:2009-12-02,参观= 13685,bouceRate = 45}
{日期:2009-12-04,参观= 68755,bouceRate = 45}
{日期:2009-12-03,参观= 35875,bouceRate = 45}
我要这个的ArrayCollection按日期排序,所以这将是从过去到present - 像这样:
{日期:2009-12-01,参观= 13555,bouceRate = 45}
{日期:2009-12-02,参观= 13685,bouceRate = 45}
{日期:2009-12-03,参观= 35875,bouceRate = 45}
{日期:2009-12-04,参观= 68755,bouceRate = 45}
{日期:2009-12-05,参观= 46955,bouceRate = 45}
{日期:2009-12-06,参观= 13685,bouceRate = 45}
我已经试过,没有prevail(不排序)以下
VAR dateSort:分类=新的排序();
dateSort.fields =新的SortField(日,假的,假的,真正的);
newAreaChartData.sort = dateSort;
newAreaChartData.refresh();
// traceout
对于(VAR我:= 0; I< newAreaChartData.length;我++)
迹线(对象#+ I +:+ ObjectUtil.toString(newAreaChartData.getItemAt(ⅰ)));
解决方案
这为我工作:
为(i = 0; I< newAreaChartData.length ++我){
newAreaChartData [I] .formattedDate = getActualDate(newAreaChartData [I] .date);
newAreaChartData [I] .dateTime = newAreaChartData [I] .formattedDate.time;
跟踪(newAreaChartData [I] .dateTime);
}
VAR dateSort:分类=新的排序();
dateSort.fields =新的SortField(日期时间,假的,假的,真正的);
newAreaChartData.sort = dateSort;
newAreaChartData.refresh();
对于(VAR我:= 0; I< newAreaChartData.length;我++)
迹线(对象#+ I +:+ ObjectUtil.toString(newAreaChartData.getItemAt(ⅰ)));
I have an ArrayCollection of Objects. Each Object has the following keys/values:
{date: 2009-12-01, visits=13555, bouceRate=45}
{date: 2009-12-05, visits=46955, bouceRate=45}
{date: 2009-12-06, visits=13685, bouceRate=45}
{date: 2009-12-02, visits=13685, bouceRate=45}
{date: 2009-12-04, visits=68755, bouceRate=45}
{date: 2009-12-03, visits=35875, bouceRate=45}
I need to sort this ArrayCollection by date, so it would be from past to present - like so:
{date: 2009-12-01, visits=13555, bouceRate=45}
{date: 2009-12-02, visits=13685, bouceRate=45}
{date: 2009-12-03, visits=35875, bouceRate=45}
{date: 2009-12-04, visits=68755, bouceRate=45}
{date: 2009-12-05, visits=46955, bouceRate=45}
{date: 2009-12-06, visits=13685, bouceRate=45}
I have tried the following with no prevail (not sorting):
var dateSort:Sort = new Sort();
dateSort.fields = [new SortField("date", false, false, true)];
newAreaChartData.sort = dateSort;
newAreaChartData.refresh();
// traceout
for (var i:int = 0; i <newAreaChartData.length; i++)
trace ("Object #" + i + ": " + ObjectUtil.toString(newAreaChartData.getItemAt(i)));
解决方案
This worked for me:
for(i = 0; i < newAreaChartData.length; ++i) {
newAreaChartData[i].formattedDate = getActualDate(newAreaChartData[i].date);
newAreaChartData[i].dateTime = newAreaChartData[i].formattedDate.time;
trace(newAreaChartData[i].dateTime);
}
var dateSort:Sort = new Sort();
dateSort.fields = [new SortField("dateTime", false, false, true)];
newAreaChartData.sort = dateSort;
newAreaChartData.refresh();
for (var i:int = 0; i <newAreaChartData.length; i++)
trace ("Object #"+ i + ": " + ObjectUtil.toString(newAreaChartData.getItemAt(i)));
这篇关于动作:ArrayCollection的排序按日期:YYYY-MM-DD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!