Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Looping over complex structure

Posted on 2014-04-11
12
Medium Priority
?
187 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
Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…

609 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