|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Structures: Finding Values
Hey everyone,
I'm fairly new to coldfusion structures and I'm not sure if I'm trying to solve this problem the right way. I have a list of people. The list will include their name, a pdf path, and letter that begins their last name. I decided to put this into a nested structure. What i need to do is be able to search the structure to pull out people by the letter for their last name. For example there will be a drop down with A-Z. Then when someone selects A only those people with last name that begin with A will appear. This is my code so far. I just don't know how to pull out the index field where people have an "A" or whatever letter in there. Please help! <cfset speakers = structNew()> <cfset speakers.speaker1.name = "Daniel"> <cfset speakers.speaker1.pdf = "Daniel.pdf"> <cfset speakers.speaker1.index = "a"> <cfset speakers.speaker2.name = "Tom"> <cfset speakers.speaker2.pdf = "Tom.pdf"> <cfset speakers.speaker2.index = "b"> <cfloop collection="#speakers#" item="speaker"> <cfloop collection="#speakers[speaker]#" item="key"> #speakers[speaker][key]#<br/> </cfloop> </cfloop> |
|
#2
|
|||
|
|||
|
Could you alter the format of the structure so that it uses the first letter of their last name as the key?
<cfset speakers = structNew()> <cfset speakers.a.speaker1.name = "Daniel"> <cfset speakers.a.speaker1.pdf = "Daniel.pdf"> <cfset speakers.b.speaker1.name = "Tom"> <cfset speakers.b.speaker1.pdf = "Tom.pdf">
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
||||
|
||||
|
Have you tried StructFindValue?
|
|
#4
|
|||
|
|||
|
Ooo,
I think i see where you're going with this one. It would be putting everyone into their last by a key. Yeah I could do that. How would i pull out people in .a? I'm guessing a structure function? |
|
#5
|
|||
|
|||
|
Ok i think i've figured it out.
Thanks for your help! |
|
#6
|
|||
|
|||
|
IMHO this would be easier to accomplish with an array of structures.
<cfset variables.speakers = ArrayNew(1)> <cfloop index="variables.i" from="1" to="#someLimit#"> <cfset variables.speakers[variables.i] = structNew()> <cfset variables.speakers[variables.i].name = "Daniel"> <cfset variables.speakers[variables.i].pdf = "Daniel.pdf"> <cfset variables.speakers[variables.i].index = "a"> </cfloop> |
|
#7
|
|||
|
|||
|
It depends on what you're trying to do. If the goal is to be able to easily grab all the elements that have the same first letter in their last name, the solution you mention would actually be more complicated because you'd have to loop through the entire array to find all the elements with the same letter.
|
|
#8
|
|||
|
|||
|
That said, if the goal IS to easily get all elements with the same first letter of the last name, using a structure of arrays would probably work even better. You wouldn't have to worry about naming each element uniquely within each letter.
<cfset speakers = structNew()> <cfset speakers.a = arrayNew(1) /> <cfset speakers.a[1].name = "Daniel"> <cfset speakers.a[1].speaker1.pdf = "Daniel.pdf"> <cfset speakers.b = arrayNew(1) /> <cfset speakers.b[1].name = "Tom"> <cfset speakers.b[1].pdf = "Tom.pdf"> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Structures: Finding Values |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|