They really are unordered. So you can not be sure of the key order.
There's another problem in using the struct keys for site navigation 
scheme. Not all characters are allowed in a struct key. Sooner or later 
you're going to run into one you want in your navigation scheme but the 
struct wont accept it. And you will give yourself a very hard time if you 
want your site to be multilingual later on.

If you are aware of the risks and you dont mind using dirty tricks to make 
your code work you can always prepend your structkeys with a sort order 
and a separator, kinda like: n0001_Overview, n0002_Table Of Contents, ... 
and just show the ListLast(key,'_'). Its not proper coding, but gets the 
job done. (Do mind NOT to use _ in your navigation scheme either)

Happy coding.

Stijn Dreezen.




On Sun, 27 Feb 2005, Daniel Short wrote:

> Hi everyone,
> 
> I'm trying to use a structure to hold the navigation scheme for a site.
> Unfortunately, the fact that "structure keys are unordered" as the livedocs
> tell me, is causing a problem. Here's what I'm doing.
> 
> I use the addItem method of my CFC to add new items to my navigation.
> 
> <cfset addItem("Overview", "title.cfm")>
> <cfset addItem("Table of Contents", "toc.cfm")>
> <cfset addItem("Tasks", "tasks.cfm")>
> <cfset addItem("Details", "details.cfm")>
> <cfset addItem("Project Team", "team.cfm")>
> 
> addItem looks like so:
> 
> <cffunction name="addItem" displayName="Add Item" hint="I add a navigation
> item to a navigation block." access="public" returnType="boolean"
> output="false">
>       <cfargument name="LinkName" type="string" required="true">
>       <cfargument name="PageName" hint="The .cfm page to link to"
> type="string" required="true">
>       <cfset var local = StructNew()>
>       <cfset local.item = StructNew()>
>       <cfset StructInsert(local.item, arguments.LinkName,
> arguments.PageName)>
> 
>       <cfset setNavigation(local.item)>
> 
>       <cfreturn true>
> </cffunction>
> 
> setNavigation looks like this:
> 
> <cffunction name="setNavigation" access="private" returntype="VOID"
> output="false">
>       <cfargument name="NavItem" type="struct" required="true" hint="A
> structure containing the navigation item to add to the list">
>       <cfset StructAppend(variables.instance.navigation,
> arguments.NavItem)>   
> </cffunction>
> 
> Variables.instance.navigation holds my navigation structure. Now,
> considering the order in which I added my navigation items, I would expect
> them to be spit out in the same order. Instead they come out like so:
> 
> Details, Table of Contents, Overview, Project Team, Tasks
> 
> Now, if structs really were unordered, I would expect that they would
> occassionally come out in a *different* order, but nope... They always come
> out in the same order, WRONG! :).
> 
> Anyone have any ideas to help me crack this nut?
> 
> Thanks,
> 
> Dan
> 
> 
> 
> ----------------------------------------------------------
> You are subscribed to cfcdev. To unsubscribe, send an email to 
> [email protected] with the words 'unsubscribe cfcdev' as the subject of the 
> email.
> 
> CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
> (www.cfxhosting.com).
> 
> An archive of the CFCDev list is available at
> www.mail-archive.com/[email protected]
> 

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]

Reply via email to