【发布时间】:2021-08-08 00:31:40
【问题描述】:
我在其中一个页面中看到此代码,看起来很烦人,如果我在 Coldfusion 11 上,它可以被缩短 https://trycf.com/gist/701515844d5e41549a7b6e61dfafeaa0/lucee5?theme=monokai
这是代码的样子
<cfloop list="#mqry.columnList#" index="col">
<cfset ColRow ="#mqry.columnList#," >
</cfloop>
<cfset x = replace(ColRow,"CONDITION1","CONDITION") & chr(13) & chr(10)>
<cfloop query="mqry">
<cfloop list="#mqry.columnList#" index="colN">
<cfset f = Replace("#mqry[colN][currentRow]#" ,"""","","All")>
<cfset f = REReplaceNoCase("#mqry[colN][currentRow]#" , "<[^>]*(?:>|$)", "", "ALL")>
<cfset x = x & """#_f#"",">
</cfloop>
<cfset x = x & chr(13) & chr(10)>
</cfloop>
我认为我可以做到的第一个值:
mquery.columnlist - no need to loop over
【问题讨论】:
-
看起来您正试图从查询中生成 CSV?每个单元格值前面的下划线是故意的吗?为什么每一行都以分隔符
,结尾? -
是的,尝试生成 csv,它可以工作,但它的编写方式非常奇怪,我正在尝试简化它并从这里删除不必要的循环,我已经更新了我的要点
-
所有回车的目的是什么?
-
@DanBracuk 你指的是“CRLF vs LF”吗?因为 CSV 需要换行符,并且列标题有一个,每一行都有一个。目的应该明确。
标签: coldfusion lucee