ListAppend () not working?

I have a problem with my cfml code. The function ListAppend()does not seem to work.

Here is the code on my .cfm page:

<cfset fruitList="apple, orange, banana">

<cfoutput>
    fruitList before: #fruitList#<br>
</cfoutput>

<cfset temp = ListAppend(fruitList, "kiwi")>
<cfoutput>
    fruitList after: #fruitList#<br>
</cfoutput>

But I always get this conclusion:

fruitList before: apple, orange, banana

fruitList after: apple, orange, banana

The same goes for ListPrepend()and ListInsertAt(). Why is this happening?

Any help is appreciated.

+5
source share
3 answers

listAppend () returns a new list (lists are nothing more than strings that ColdFusion passes by value), so in order for you to see the added value, you will need to use:

<cfset fruitlist = ListAppend(fruitList, "kiwi") />
+29
source

Try

<cfset fruitList="apple, orange, banana">

<cfoutput>
fruitList before: #fruitList#<br>
</cfoutput>

<cfset fruitList=ListAppend(fruitList, "kiwi")>

<cfoutput>
fruitList after: #fruitList#<br>
</cfoutput>

cfquickdocs listAppend , . http://cfquickdocs.com/#ListAppend

, .

+8

In fact, in your example, you are simply adding a list. However, you create a new temp list and copy the contents of the fruit list, and then add the kiwi.

<cfset temp = ListAppend(fruitList, "kiwi")>

If you want to reset the topic list, you will see the list you want to see.

<cfdump var="#temp#">
+6
source

All Articles