?
Solved

Looping over complex structure

Posted on 2014-04-11
12
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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 2000 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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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