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

cfloop : to annotate the different elements of a list

Contributor ,
Aug 20, 2017 Aug 20, 2017

Copy link to clipboard

Copied

Hello,

I would like to be able to annotate the different elements of a list made with a cfloop.

I do not know how to do it.

Thank you for your help.
cfloop.gif

Views

296

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
Community Expert ,
Aug 21, 2017 Aug 21, 2017

Copy link to clipboard

Copied

LATEST

It's unclear what you mean by "annotate the different elements of a list". By definition, each element in a list has a position. Couldn't you use that as annotation?

In any case, you could store the list elements in an array. It would then take just one function call to convert back to list. The thinking goes like this

<cfset elements = arrayNew(1)>

<cfloop index="idx" from="1" to="5">

    <cfswitch expression="#idx#">

        <cfcase value="1" >

            <cfset elements[idx] = "Genre">

        </cfcase>

        <cfcase value="2" >

            <cfset elements[idx] = "Nom">

        </cfcase>

        <cfcase value="3" >

            <cfset elements[idx] = "Prénom">

        </cfcase>

        <cfcase value="4" >

            <cfset elements[idx] = "Code postal">

        </cfcase>

        <cfcase value="5" >

            <cfset elements[idx] = "Ville :">

        </cfcase>          

    </cfswitch>

</cfloop>

<cfoutput>#arrayToList(elements)#</cfoutput>

Votes

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