2010-06-14 91 views
2

我有一个数组项[] items []中的每个项目都是一个结构体。 项目有按键标识,日期,金额(即item.id,item.date,item.value)Coldfusion 8:结构体结构数组结构体

我想用StructSort按日期

到项目收集整理这是最好的方法做到这一点在ColdFusion的8:

<cfset allStructs = StructNew()> 
<cfloop array = #items# index = "item"> 
    <cfset allStructs[item.id] = item> 
    <cfset unixtime = DateDiff("s", CreateDate(1970,1,1), item.date)> 
    <cfset allStructs[item.id].unixtime = unixtime> 
</cfloop> 
<cfset allStructs = StructSort(allStructs, "numeric", "desc", "unixtime")> 

这将是可怕缓慢

+3

它有多慢?您也可以将其转换为查询并使用Query-of-queries对其进行排序。可能会更快。 – 2010-06-14 23:31:03

回答

3

您仍然需要转换为unixtime,但ArrayOfStructsSort可能会更快。至少你可以比较两个选项。

+0

Ooooh谢谢。我会做一个比较。现在我决定将已排序的结构体缓存到会话中,因此只有会话的初始加载速度较慢(〜3-5s avg)。 (也不使用应用程序范围,因为这些都是会话特定的值,我不需要一堆疯狂的锁定) – davidosomething 2010-06-15 00:59:43