Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Nested loops with arrays

Enthusiast ,
Feb 15, 2016 Feb 15, 2016

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

386
Translate
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

Enthusiast , 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>

Translate
Enthusiast ,
Feb 15, 2016 Feb 15, 2016
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>

Translate
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
Resources