我用JSON将查询结果输出到file.txt。每次单击“submit”(表单)并根据其更新查询的变量进行更新时,都会更新该文件。
现在这个表只有大约20个记录,而且可能每天增加2/3的新记录。
是否有更好的方法来更新文件test.txt,从查询中获取结果?
<cfsavecontent variable="mytest">
[
<cfoutput query="getimeline">
<cfif (getimeline.CurrentRow EQ getimeline.RecordCount)>
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"}
<cfelse>
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"},
</cfif>
</cfoutput>
]
</cfsavecontent>
<cffile action="write" file="C:test.txt" output="#mytest#"> [
{"title":"Advance pay Rollovers","date":"October 23, 2015"},
{"title":"New Card Ordering Process 1","date":"December 28, 2015"},
{"title":"about about","date":"February 5, 2016"}
]发布于 2015-11-06 21:53:48
我不知道sqat关于冷融合,但似乎您可以消除一些重复:
<cfsavecontent variable="mytest">
[
<cfoutput query="getimeline">
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"}<cfif (getimeline.CurrentRow NEQ getimeline.RecordCount)>,</cfif>
</cfoutput>
]
</cfsavecontent>
<cffile action="write" file="C:test.txt" output="#mytest#"> 如果您不介意将逗号放在下一行,那么您可以使用这种更具可读性的写作风格:
<cfsavecontent variable="mytest">
[
<cfoutput query="getimeline">
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"}
<cfif (getimeline.CurrentRow NEQ getimeline.RecordCount)>,</cfif>
</cfoutput>
]
</cfsavecontent>
<cffile action="write" file="C:test.txt" output="#mytest#"> https://codereview.stackexchange.com/questions/110054
复制相似问题