Solved

Looping over complex structure

Posted on 2014-04-11
12
178 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
Question by:myselfrandhawa
  • 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:myselfrandhawa
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:myselfrandhawa
ID: 39995131
Let me try
0
 
LVL 15

Author Comment

by:myselfrandhawa
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 15

Author Comment

by:myselfrandhawa
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:myselfrandhawa
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:myselfrandhawa
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:myselfrandhawa
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:myselfrandhawa
ID: 39996586
ok that worked

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

Open in new window

0
 
LVL 15

Author Closing Comment

by:myselfrandhawa
ID: 39998557
Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

17 Experts available now in Live!

Get 1:1 Help Now