【发布时间】:2010-10-26 07:45:06
【问题描述】:
我在 ColdFusion 中有一个半大型(数百条记录)一维数组。数组中的每一项都是具有多个属性的结构。我想在数组中搜索具有特定“名称”属性的结构。我知道对于字符串值数组,我可以使用如下 Java 方法:
<cfset arrayIndex = myArray.indexOf("WhatImLookingFor") + 1>
...但这不适用于结构数组。我也知道我可以像这样暴力破解它:
<cfset arrayIndex = 0>
<cfloop from="1" to="#ArrayLen(myArray)#" index="counter">
<cfif myArray[counter].name IS "WhatImLookingFor">
<cfset arrayIndex = counter>
</cfif>
</cfloop>
...但我觉得必须有更有效的方法。有没有人有比这更好的解决方案?您可以假设“name”属性存在于每个结构中,并且数组中没有间隙或其他对象。
【问题讨论】:
标签: algorithm arrays search coldfusion struct