Ha... wish I had though of that a couple of weeks ago and would have
saved myself a rewrite of existing code!
Good tip!

-----Original Message-----
From: Brad Roberts 
Sent: 31 July 2003 16:27
To: CF-Talk
Subject: RE: Preserve collection order


Hard code the list of struct keys... putting it into the structure
itself might help you remember to update the list when you add a key to
the struct.

--------------------
<cfset instance["orderedKeyList"] =
"id,manufacturer_name,name,parttype_name,status_name">

<cfoutput>
 <cfloop list="#instance.orderedKeyList#" index="i">
  #instance[i].heading# - #instance[i].size# <br />
 </cfloop>
</cfoutput>
--------------------

-Brad

> -----Original Message-----
> From: Suyer, Ed [PRD Non-J&J] [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 31, 2003 10:55 AM
> To: CF-Talk
> Subject: Preserve collection order
>
>
> Hi folks,
>
> Does anyone know of a way to preserve the order of keys in a structure

> so that it matches the order in which it was created?
>
> i.e.
>
> I created a structure that looks like so:
>
> instance structNew();
>
> instance["id"] = structNew();
> instance["id"].heading = "Id";
> instance["id"].size = 50;
>
> instance["manufacturer_name"] = structNew(); 
> instance["manufacturer_name"].heading = "MFG"; 
> instance["manufacturer_name"].size = 200;
>
> instance["name"] = structNew();
> instance["name"].heading = "Name";
> instance["name"].size = 100;
>
> instance["parttype_name"] = structNew(); 
> instance["parttype_name"].heading = "Part Type"; 
> instance["parttype_name"].size = 100;
>
> instance["status_name"] = structNew(); instance["status_name"].heading

> = "Status"; instance["status_name"].size = 100;
>
> When I cfloop through it ( i.e. for ( field in instance ) {} ), I 
> would expect it to find the "id" field first, then 
> "manufacturer_name", and so on and so fourth in the order in which the

> structure was created.  Instead it loops through in this order:
> name,id,parttype_name,manufacturer_name,status_name
>
> I figured I'd try to trick it by doing a structKeyList() then 
> cflooping through that, but it returns the same thing: 
> name,id,parttype_name,manufacturer_name,status_name
>
> Does anyone know of a way to cfloop through this structure in the 
> order in which it was created: 
> id,manufacturer_name,name,parttype_name,status_name ?
>
> TIA!
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Get the mailserver that powers this list at 
http://www.coolfusion.com

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to