Solved

Looping over complex structure

Posted on 2014-04-11
12
180 Views
Last Modified: 2014-04-14
I have the following complex structure and i want to loop over the skills structure which is having value of arrays and structs inside and again arrays

so i have not started anything yet, need to know what could be the start

I am attaching a screenshot, basically what i all trying is to fetch all the skills in a list format.

here is the screenshot

http://s28.postimg.org/dhfm5b8vx/cfstructs.png

i tried like this:

<cfloop collection="#skills#" item="Ticker">
<cfoutput>
<tr>
  <td>#Ticker#</td>
</tr>
</cfoutput>
0
Comment
  • 9
  • 3
12 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 39994974
Looks like the array is inside of Values

<cfset theArray = skils.values>

<cfloop index="aSkill" from=1 to="#arrayLen(theArray)#">

    <cfdump var="#aSkill#">

</cfloop>
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39995019
@gd, the skills is not an array, its a part of a of a big structure,

so it is like this:

struct - skills then: values containing another set set of arrays and inside that array i have another set of structures and when you see the [skill structure again], you will see another set of structure which is NAME

so i need name to be in the list by comma separated..

I hope i had made it clear
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 39995123
I see that skills is not an array, that's why I pulled the array from "values"  but perhaps the array is called "me" inside of values like this...

<cfset theArray = skils.values.me>  <!--- put the array into another variable for easy handling --->

<cfloop index="aSkill" from=1 to="#arrayLen(theArray)#">

    <cfdump var="#aSkill#">

    The ID is  #aSkill.ID#  and the name is #aSkill.skill.name# <br>

</cfloop>
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39995131
Let me try
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39995172
Here is the Dump i am using

<cfdump var="#getMe()#" label="me" expand="false">

I am getting the variable skills is undefined

Here is the screenshot of where the actual struct is coming from

http://screencast.com/t/ywsjydQamTPL

Please note, the struct is starting with me.

even i tried like this

<cfset theArray = me.skills.values.me>

it is then saying variable me is undefined. why this happening
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 39995588
This looks like the structure is coming from a function ()  

    <cfdump var="#getMe()#" label="me" expand="false">

So, let's assign it to a variable...


 <cfset myStruct = getMe()>


From the image, my guess is that this will return a dump of values..

 <cfdump var="#myStruct.skills#">


If it does, then just test one level at a time and see that you are right...

 <cfdump var="#myStruct.skills.values#">


Does that return a dump of values or an error?

Is it an array?  If yes, then assign it into TheArray variable here....
If it is not, test another dump to determine the name of the next level... is it "me" ?


<cfset theArray = myStruct.skills.values>  <!--- put the array into another variable for easy handling --->

<cfloop index="aSkill" from=1 to="#arrayLen(theArray)#">

    <cfdump var="#aSkill#">

    The ID is  #aSkill.ID#  and the name is #aSkill.skill.name# <br>

</cfloop>
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39995674
seems working, but it is showing error on this line

You have attempted to dereference a scalar variable of type class java.lang.Double as a structure with members.

The ID is  #aSkill.ID#  and the name is #aSkill.skill.name# <br>
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39995725
ok, this seems working

 The ID is  #theArray[aSkill].ID#  and the name is #theArray[aSkill].skill.name# <br>

or

<cfloop index="i" array="#theArray#">

    <cfdump var="#i#">

    The ID is  #i.ID#  and the name is #i.skill.name# <br>

</cfloop>

Open in new window

0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39995731
stil i need to check if the

<cfset theArray = me.skills.values> is not null or not defined or not empty..

What i would possibly be adding here
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39995915
not sure what is going wrong here, but does this statement stands true:

<cfif StructKeyExists(theArray[aSkill].company,"theArray[aSkill].company.industry")>
            <cfset Industry = "Industry: #theArraypos[aSkill].company.industry#">
    <cfelse>
          <cfset Industry = ''>    
    </cfif>

even if defined, it is showing as empty
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 39996586
ok that worked

<cfif StructKeyExists(theArray[aSkill].company,"industry")>

Open in new window

0
 
LVL 16

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 39998557
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question