Solved

Looping over complex structure

Posted on 2014-04-11
12
179 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 15

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
 
LVL 15

Author Comment

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

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 15

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 15

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 15

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 15

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 15

Author Comment

by:Gurpreet Singh Randhawa
ID: 39996586
ok that worked

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

Open in new window

0
 
LVL 15

Author Closing Comment

by:Gurpreet Singh Randhawa
ID: 39998557
Thanks
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
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 …
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 …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now