Last active
August 29, 2015 14:01
-
-
Save ryanguill/bd92e8a7954076fd13af to your computer and use it in GitHub Desktop.
how to create an ordered struct in Adobe ColdFusion and Railo - run this code here: http://www.trycf.com/scratch-pad/gist/bd92e8a7954076fd13af/railo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <cfscript> | |
| //In Adobe ColdFusion | |
| //instead of structNew() or {} create a java linked hashmap | |
| myStruct = createObject( "java", "java.util.LinkedHashMap" ).init(); | |
| //now just use it like any other struct | |
| //NOTE: one difference though is that it will be case sensitive, myStruct["one"] will be different than myStruct["One"] | |
| //unlike normal cf structures | |
| //In railo you can do it like the adobe example or use this shorthand | |
| myStruct = structNew("linked"); | |
| //again, then just use it like any other struct | |
| //in either case, when looping over the structure the keys will always be in the order they were created | |
| //http://classic.railo.ch/en/index.cfm?treeID=177 | |
| //you can also create a weak hash map which can have some memory performance benefits depending on what youre doing | |
| myStruct["three"] = 3; | |
| myStruct["two"] = 2; | |
| myStruct["one"] = 1; | |
| </cfscript> | |
| <cfoutput> | |
| <cfloop collection="#myStruct#" item="key"> | |
| #key#:#myStruct[key]#<br /> | |
| </cfloop> | |
| </cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment