So konvertieren Sie die Abfragespalte in eine Liste in ColdFusion
-
14-11-2019 - |
Frage
Ich versuche, ColdFusion-Abfragespalte in eine Liste zu konvertieren, was ist der beste Weg, um dies zu tun?
Ich dachte, dass es eine eingebaute Funktion gibt, mit der es sich ermöglicht, eine Abfragespalte einfach in eine Liste zu konvertieren, wenn das, was ist, was ist, was ist?
Lösung
There is a built-in function to do that: ValueList
<cfset myList = ValueList(query.columnname)>
As with all of the list functions, there's an optional delimiter attribute.
<cfset myList = ValueList(query.columnname,"|")>
If you need the values in the list to have double-quotes around them, use QuotedValueList.
<cfset myList = QuotedValueList(query.columnname)>
Andere Tipps
You can also access a query's columns as arrays directly without any conversion if that works for what you're trying to do:
qry.col[1] // col field of first record
qry.col[2] // col field of second record
...
or
qry["col"][1] // col field of first record
qry["col"][2] // col field of second record
A CF query object is really an associative array of columns... weird but occasionally useful.
How about in a case like this:
<cfset SummaryQuery = Evaluate('getReportData' & summaryName & 'Summary') />
<cfset TypeList = ArrayToList(SummaryQuery[subsectionName & 'Type']) />
vs.
<cfset QueryColumn = SummaryQuery[subsectionName & 'Type'] />
<cfset TypeList = ValueList(QueryColumn) />