【问题标题】:Coldfusion 8: Array of structs to struct of structsColdfusion 8:结构数组到结构结构
【发布时间】:2010-06-14 23:14:24
【问题描述】:

我有一个数组 items[] items[] 中的每个项目都是一个结构。 item 有键 id、date、value(即 item.id、item.date、item.value)

我想使用 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")>

它会非常缓慢

【问题讨论】:

  • 有多慢?您还可以将其转换为查询并使用 Query-of-queries 对其进行排序。可能会更快。

标签: arrays sorting coldfusion struct coldfusion-8


【解决方案1】:

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

【讨论】:

  • 哦,谢谢。我来做个对比。现在我决定将排序后的结构缓存到会话中,因此只有会话的初始加载很慢(平均约 3-5 秒)。 (也不使用应用程序范围,因为这些已经是特定于会话的值,我不需要一堆疯狂的锁定)
猜你喜欢
  • 1970-01-01
  • 2015-07-02
  • 1970-01-01
  • 2015-01-06
  • 2013-07-29
  • 2017-06-10
  • 1970-01-01
  • 2018-11-28
  • 1970-01-01
相关资源
最近更新 更多