ColdFusion的 - 如何通过结构并打印出动态的所有关键值的数组循环? [英] Coldfusion - How to loop through an Array of Structure and print out dynamically all KEY values?
问题描述
捐赠以下结构的数组:
我能够做打印出来自各个领域的所有值:
< CFSET COLUMNNAMES = structKeyArray(ApiData [1])>
< CFSET ColumnLength = ArrayLen(COLUMNNAMES)GT; <从=1=#ArrayLen(ApiData)#指数=我&GT CFLOOP;
< cfdump VAR =#ApiData [I] .Created#>
< cfdump VAR =#ApiData [I] .Name点#>
...等等
现在,我通过各个领域的尝试循环,这样我不必实际写入
命名每个字段。如何动态地做到这一点?
是这样的:
<从=1=#ArrayLen(ApiData)#指数=我&GT CFLOOP;
< CFLOOP从=1=#ColumnLength#指数=我>
<! - < cfdump VAR =#ApiData [1]。 +#ColumnNames [I]#+#> --->
<! - < cfdump VAR =#ApiData [I] .ColumnNames [I]#>&--- GT;
< / CFLOOP>
< / CFLOOP>
我不是一个ColdFusion的家伙,只是帮助好友和ColdFusion的语法与净很大的不同: - )
感谢您的帮助。
< CFLOOP从=1=#arrayLen(ApiData)#指数=我&GT ;
< CFSET数据= ApiData [I]>
< CFLOOP集合=#数据#项=键>
#键#:#数据[关键]#
< / CFLOOP>
< / CFLOOP>
或者可以使用CFSCRIPT,这应该是很容易回升。
为(D IN ApiData)// for-in循环数组
{
对(在D键)// for-in循环的结构
{
writeOutput(钥匙&安培;:和D [关键]);
}
}
使用此链接: http://www.learncfinaweek.com/week1/Looping/
Giving the Array of Structure below:
I am able to print out all values from all fields by doing:
<cfset ColumnNames = structKeyArray(ApiData[1])>
<cfset ColumnLength = ArrayLen(ColumnNames)>
<cfloop from="1" to="#ArrayLen(ApiData)#" index="i">
<cfdump var="#ApiData[i].Created#">
<cfdump var="#ApiData[i].Name#">
...and so on
Now I am trying to loop through all fields so that I dont have to actually write the name of each field. How do I do this dynamically? Something like:
<cfloop from="1" to="#ArrayLen(ApiData)#" index="i">
<cfloop from="1" to="#ColumnLength#" index="i">
<!---<cfdump var="#ApiData[i]." + "#ColumnNames[i]#" + "#">--->
<!---<cfdump var="#ApiData[i].ColumnNames[i]#">--->
</cfloop>
</cfloop>
I am not a ColdFusion guy, just helping a buddy and the ColdFusion syntax is very different from .Net :-)
Thank you for your help
<cfloop from="1" to="#arrayLen(ApiData)#" index="i">
<cfset data = ApiData[i]>
<cfloop collection="#data#" item="key">
#key#:#data[key]#
</cfloop>
</cfloop>
Or you can use CFScript, which should be much easier to pick up.
for (d in ApiData) // for-in loop for array
{
for (key in d) // for-in loop for struct
{
writeOutput(key & ":" & d[key]);
}
}
use this link: http://www.learncfinaweek.com/week1/Looping/
这篇关于ColdFusion的 - 如何通过结构并打印出动态的所有关键值的数组循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!