Posted By


daspoda on 08/22/12

Tagged


Statistics


Viewed 154 times
Favorited by 0 user(s)

renameForCompositeKey


/ Published in: ColdFusion
Save to your folder(s)

RenameForCompositeKey

Helps with creating new composite key objects by renaming the keys to include a blank id

@structure, structure to rename keys on
@keyPosition, position of the provided key


Copy this code and paste it in your HTML
  1. <cffunction name="renameForCompositeKey" returntype="struct">
  2. <cfargument name="structure" required="yes">
  3. <cfargument name="keyPosition" required="yes" type="numeric">
  4. <cfset LOCAL = StructNew()>
  5.  
  6. <!--- create temporary structure copy --->
  7. <cfset LOCAL.temp = structure>
  8.  
  9. <!--- clear structure --->
  10. <cfset structure = StructNew()>
  11.  
  12. <!--- loop through keys, and repopulate struct --->
  13. <cfloop collection="#LOCAL.temp#" item="key">
  14. <cfif keyPosition EQ 1>
  15. <cfset structure["#key#,"] = LOCAL.temp[key]>
  16. <cfelse>
  17. <cfset structure[",#key#"] = LOCAL.temp[key]>
  18. </cfif>
  19. </cfloop>
  20. <cfreturn structure>
  21. </cffunction>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.