I am using cfloop to loop over a structure and outputting it's key
values pairs as a simple form check box list.
The problem is that the output is no longer sorted in the proper order
when I loop over the structure. The cfmx7 migration PDF from Adobe says
that the behavior for CFloop changed in CFMX7 and it loops in the order
the structure was created instead of auto sorting.
From the PDF.
"cfloop
Change
ColdFusion MX ColdFusion MX returns struct keys in the order that you
create them. ColdFusion 5 returns struct keys in alphabetical order.
To sort struct values or keys, use the StructSort and StructKeySort
functions."
I have noticed that cfmx 7.02 Enterprise does not follow this rule.
Also, the StructKeySort function seems to be MIA. I have created a work
around, but I thought I'd mention this here since the behavior does not
seem to match the the documentation. Either it never did, or it was
changed and the docs never changed. Or hey, there could be newer docs
that specify the change that I haven't seen. I'm curious and would like
to know what is really supposed to happen.
The structure is very simple and gets populated from an alpha ordered
query. Even when I create the structure manually I get the same messed
up output. The odd thing is CFDUMP outputs the structure sorted by key
name.
The Code:
<cfset serverlist = structnew()>
<cfset serverlist["Integrated1"] = "I1">
<cfset serverlist["Mlsfinder1"] = "m1">
<cfset serverlist["Mlsfinder2"] = "m2">
<cfset serverlist["Mlsfinder3"] = "m3">
<cfset serverlist["Mlsfinder4"] = "m4">
<cfset serverlist["Mlsfinder5"] = "m5">
<cfset serverlist["Mlsfinder6"] = "m6">
<cfloop collection="#serverlist#" item="theservername">
<cfoutput>#theservername#</cfoutput><br />
</cfloop>
<cfdump var="#serverlist#">
<!--- this line errors out --->
<cfset sorted = StructKeySort(serverlist,'TextNoCase','Asc')>
Server info:
Server Product ColdFusion MX
Version 7,0,2,142559
Edition Enterprise
Operating System UNIX
OS Version 2.6.9-42.0.10.ELsmp
Thanks,
--
Wil Genovese
One man with courage makes a majority.
-Andrew Jackson
A fine is a tax for doing wrong. A tax is a fine for doing well.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
The most significant release in over 10 years. Upgrade & see new features.
http://www.adobe.com/products/coldfusion?sdid=RVJR
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:282087
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4