CFMX Structure Sorting
OK, so I've read the livedocs explaining the changes to the way structures behave in MX, but I'm not finding it to be the case... here's what the docs say: "ColdFusion MX returns struct keys in the order that you create them. ColdFusion 5 returns struct keys in alphabetical order. If you need sorted struct values or keys, use the StructSort() and StructKeySort() functions." I have the following code to create a structure for navigation: opts = structnew(); opts[0]=structnew(); opts[0]["fa"]="foo"; opts[0]["lab"]="Option A"; opts[0]["dsc"]="My Description."; opts[1]=structnew(); opts[1]["fa"]="foo"; opts[1]["lab"]="Editor"; opts[1]["dsc"]="Add, edit, and delete."; opts[2]=structnew(); opts[2]["fa"]="enewsmailings.main"; opts[2]["lab"]="Creator"; opts[2]["dsc"]="Tools for creating things."; __ Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: CFMX Structure Sorting
The doc is talking about the changes to StructKeyList. In CF5, the list was sorted. In MX, it's the order you enter them. #structKeyList(test)# In CFMX, this returns b,a - in CF5, it returns a,b. === Raymond Camden, ColdFusion Jedi Master for Hire Email: [EMAIL PROTECTED] Yahoo IM : cfjedimaster "My ally is the Force, and a powerful ally it is." - Yoda > -Original Message- > From: Sean Daniels [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, September 18, 2002 3:31 PM > To: CF-Talk > Subject: CFMX Structure Sorting > > > OK, so I've read the livedocs explaining the changes to the way > structures behave in MX, but I'm not finding it to be the case... > here's what the docs say: > > "ColdFusion MX returns struct keys in the order that you create them. > ColdFusion 5 returns struct keys in alphabetical order. If you need > sorted struct values or keys, use the StructSort() and > StructKeySort() > functions." > > I have the following code to create a structure for navigation: > > > opts = structnew(); > opts[0]=structnew(); > opts[0]["fa"]="foo"; > opts[0]["lab"]="Option A"; > opts[0]["dsc"]="My Description."; > opts[1]=structnew(); > opts[1]["fa"]="foo"; > opts[1]["lab"]="Editor"; > opts[1]["dsc"]="Add, edit, and delete."; > opts[2]=structnew(); > opts[2]["fa"]="enewsmailings.main"; > opts[2]["lab"]="Creator"; > opts[2]["dsc"]="Tools for creating things."; > > __ Get the mailserver that powers this list at http://www.coolfusion.com FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
Re: CFMX Structure Sorting
On Wednesday, September 18, 2002, at 03:31 PM, Sean Daniels wrote: > OK, so I've read the livedocs explaining the changes to the way > structures behave in MX, but I'm not finding it to be the case... > here's what the docs say: > > "ColdFusion MX returns struct keys in the order that you create them. > ColdFusion5 returns struct keys in alphabetical order. If you need > sorted struct values or keys, use the StructSort() and StructKeySort() > functions." > > I have the following code to create a structure for navigation: > > > opts = structnew(); > opts[0]=structnew(); > opts[0]["fa"]="foo"; > opts[0]["lab"]="Option A"; > opts[0]["dsc"]="My Description."; > opts[1]=structnew(); > opts[1]["fa"]="foo"; > opts[1]["lab"]="Editor"; > opts[1]["dsc"]="Add, edit, and delete."; > opts[2]=structnew(); > opts[2]["fa"]="enewsmailings.main"; > opts[2]["lab"]="Creator"; > opts[2]["dsc"]="Tools for creating things."; > The list hacked my message apart. Here's the rest: When I loop over this top level struct, I would expect my results to come out the order they were created, but instead they are seemingly sorted alphabetically by the "dsc" key: #opts[ii]['lab']##opts[ii]['dsc']# __ Your ad could be here. Monies from ads go to support these lists and provide more resources for the community. http://www.fusionauthority.com/ads.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: CFMX Structure Sorting
If you look at the values for lab, you will see opts[0]["lab"] = "Option A": opts[1]["lab"] = "Editor" opts[2]["lab"] = "Creator" You looped over Opts, so it returns 0,1,2, which would be Option A,Editor,Creator which probably made you think it was going text/desc. However, you were looping over OPTs, where the keys are 0,1, and 2. === Raymond Camden, ColdFusion Jedi Master for Hire Email: [EMAIL PROTECTED] Yahoo IM : cfjedimaster "My ally is the Force, and a powerful ally it is." - Yoda > -Original Message- > From: Sean Daniels [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, September 18, 2002 4:27 PM > To: CF-Talk > Subject: Re: CFMX Structure Sorting > > > On Wednesday, September 18, 2002, at 03:31 PM, Sean Daniels wrote: > > > OK, so I've read the livedocs explaining the changes to the way > > structures behave in MX, but I'm not finding it to be the case... > > here's what the docs say: > > > > "ColdFusion MX returns struct keys in the order that you > create them. > > ColdFusion5 returns struct keys in alphabetical order. If you need > > sorted struct values or keys, use the StructSort() and > StructKeySort() > > functions." > > > > I have the following code to create a structure for navigation: > > > > > > opts = structnew(); > > opts[0]=structnew(); > > opts[0]["fa"]="foo"; > > opts[0]["lab"]="Option A"; > > opts[0]["dsc"]="My Description."; > > opts[1]=structnew(); > > opts[1]["fa"]="foo"; > > opts[1]["lab"]="Editor"; > > opts[1]["dsc"]="Add, edit, and delete."; > > opts[2]=structnew(); > > opts[2]["fa"]="enewsmailings.main"; > > opts[2]["lab"]="Creator"; > > opts[2]["dsc"]="Tools for creating things."; > > > > The list hacked my message apart. Here's the rest: > > When I loop over this top level struct, I would expect my results to > come out the order they were created, but instead they are seemingly > sorted alphabetically by the "dsc" key: > > > #opts[ii]['lab']##opts[ii]['dsc']# > > __ Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
Re: CFMX Structure Sorting
On Wednesday, September 18, 2002, at 05:18 PM, Raymond Camden wrote: > If you look at the values for lab, you will see > opts[0]["lab"] = "Option A": > opts[1]["lab"] = "Editor" > opts[2]["lab"] = "Creator" > > You looped over Opts, so it returns 0,1,2, which would be > > Option A,Editor,Creator > > which probably made you think it was going text/desc. However, you were > looping over OPTs, where the keys are 0,1, and 2. Well my last post got truncated as well. What you didn't see was the result was not what you (and I expected). The outcome was actually: Editor Add, edit, and delete. Option A My Description. Creator Tools for creating things. ANy thoughts? I would like to force the output in order of creation, or worse case in order by the top level key (which is the same obviously). I also tried this StructKeySort() function the livedocs reference and no such function seems to exist. Is this a typo in the livedocs? __ Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: CFMX Structure Sorting
Interesting. For whatever reason, the result of structKeyList or cfloop/item is not in the same order as you entered it. Maybe because of the bracket notation instead of dot notation. Anyway - the solution is simple: This will return keys in sorted order. FYI - any reason why opts is a struct and not an array? If you plan on using numbers for the keys, it may be more appropriate to use an array. === Raymond Camden, ColdFusion Jedi Master for Hire Email: [EMAIL PROTECTED] Yahoo IM : cfjedimaster "My ally is the Force, and a powerful ally it is." - Yoda > -Original Message- > From: Sean Daniels [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, September 18, 2002 8:21 PM > To: CF-Talk > Subject: Re: CFMX Structure Sorting > > > On Wednesday, September 18, 2002, at 05:18 PM, Raymond Camden wrote: > > > If you look at the values for lab, you will see > > opts[0]["lab"] = "Option A": > > opts[1]["lab"] = "Editor" > > opts[2]["lab"] = "Creator" > > > > You looped over Opts, so it returns 0,1,2, which would be > > > > Option A,Editor,Creator > > > > which probably made you think it was going text/desc. > However, you were > > looping over OPTs, where the keys are 0,1, and 2. > > Well my last post got truncated as well. What you didn't see was the > result was not what you (and I expected). The outcome was actually: > > Editor > Add, edit, and delete. > > Option A > My Description. > > Creator > Tools for creating things. > > ANy thoughts? I would like to force the output in order of > creation, or > worse case in order by the top level key (which is the same > obviously). > > I also tried this StructKeySort() function the livedocs reference and > no such function seems to exist. Is this a typo in the livedocs? > > __ Get the mailserver that powers this list at http://www.coolfusion.com FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists