Coldfusion serializeJSON example

2019-05-29 19:19发布

问题:

I'd like to see a simple template example with SerializeJSON and deserializeJSON posting to the same template and an Array adding each time a pass occurs. I've tried this several times and I keep getting confused by the pass.

回答1:

<cfif structKeyExists(form,"jsonArray")>
    <cfset arrayData = deserializeJSON(form.jsonArray) />
    <cfset arrayAppend(arrayData,form.theText) />
<cfelse>
    <cfset arrayData = [] />
</cfif>
<cfoutput>
    <form name="input" action="ableto.cfm" method="post">
        <input type="hidden" value='#serializeJSON(arrayData)#' name="jsonArray" id="jsonArray" />
        Text: <input type="text" value="" name="theText" id="theText" />
        <input type="submit" value="Subby" />
    </form>
</cfoutput>

<cfdump var="#arrayData#" />
<cfdump var="#form#" />