Nested loops with arrays

Engaged ,
Feb 15, 2016 Feb 15, 2016

Copy link to clipboard

Copied

This is my current and outer cfloop. How many nested cfloops do I need to get to data.current_version.en.text field? My guess is two loops but I'm not sure about specifying the value for the "to" in the cfloop.

<cfif structKeyExists(cfData, 'data')>

        <cfoutput>

            <cfloop index="i" from ="1" to="#arrayLen(cfData.data)#">               

            <h1>#cfData.data.searchTitle.en#</h1>

            <p>#cfData.data.current_version.en.text#</p>

            </cfloop>

        </cfoutput>

    </cfif> 

And this is what the struct looks like.

ColdFusion-Array.png

Views

212

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Engaged , Feb 15, 2016 Feb 15, 2016
Okay, got it work.<cfif structKeyExists(cfData, 'data')>        <cfoutput>            <cfloop index="i" from ="1" to="#arrayLen(cfData.data)#">                <h1>#cfData.data.name#</h1>                <p>#cfData.data.current_version.en.text#</p>            </cfloop>        </cfoutput></cfif>

Likes

Translate

Translate
Engaged ,
Feb 15, 2016 Feb 15, 2016

Copy link to clipboard

Copied

LATEST

Okay, got it work.

<cfif structKeyExists(cfData, 'data')>

        <cfoutput>

            <cfloop index="i" from ="1" to="#arrayLen(cfData.data)#">

                <h1>#cfData.data.name#</h1>

                <p>#cfData.data.current_version.en.text#</p>

            </cfloop>

        </cfoutput>

</cfif>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines