Coldfusion 8:结构数组到结构结构
我有一个数组 items[] items[] 中的每个项目都是一个结构体。 item 有键 id、date、value(即 item.id、item.date、item.value)
我想使用 StructSort 按日期对 item 集合进行排序
操作的最佳方法吗:
<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")>
这是在 ColdFusion 8 中执行此 慢得可怕
I've got an array items[]
Each item in items[] is a struct.
item has keys id, date, value (i.e., item.id, item.date, item.value)
I want to use StructSort to sort the item collection by a date
Is this the best way to do it in 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")>
It's going to be dreadfully slow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您仍然需要转换为 unixtime,但 ArrayOfStructsSort 可能会更快。至少您可以比较这两个选项。
You will still need to convert to unixtime, but ArrayOfStructsSort might be faster. At least you can compare the two options.