【发布时间】:2016-03-24 04:02:02
【问题描述】:
我曾经在屏幕上输出这个二维数组后看起来像这样:
array
1
array
1 0600
2
array
1 0
3
array
1 0600
4
array
1 0
5
array
1 0615
6
array
1 0
7
array
1 0615
8
array
1 0
9
array
1 0630
10
array
1 0
11
array
1 0630
12
array
1 1
所以我想按这个顺序循环遍历我的数组和输出值:
0600 0
0600 0
0615 0
0615 0
0630 0
0630 1
这是我创建数组的代码:
<cfloop list="#ListGetAt(dataList,i,",")#" index="z" delimiters="|">
<cfoutput query="getR" group="theYear">
<cfset name = myArray.append([z])>
<cfif Description eq z>
<cfset count = myArray.append([theCount])>
<cfelse>
<cfset count = myArray.append([0])>
</cfif>
</cfoutput>
</cfloop>
那么我现在如何循环以按照我在上面向您展示的顺序获取这两条记录?我试过了,但是没有用:
<cfoutput>
<cfloop from="1" to="#arraylen(myArray)#" index="i">
<cfloop array="#myArray#" index="j">
#i# - #myArray[1][j]#<br/>
</cfloop>
</cfloop>
</cfoutput>
编辑:当我使用这段代码时:
<cfloop array="#myArray#" index="i">
<cfloop array="#myArray#" index="j">
<cfoutput> #myArray[i][j]#<br/> </cfoutput>
</cfloop>
</cfloop>
我收到了这个错误:
The value coldfusion.runtime.Array cannot be converted to a number.
如果有人可以帮助解决这个问题,请告诉我。
【问题讨论】:
-
我不是冷融合的人,但你不应该用 [i][j] 来索引,例如#myArray[i][j] 不是 1 和 j
-
旁注,短语不起作用: 并没有告诉我们太多信息。虽然我怀疑 user5976242 是正确的,但请尝试包含对实际结果的描述,特别是它与您的预期有何不同。
-
当我使用这段代码时:
我得到了这个错误:值coldfusion.runtime.Array 无法转换为数字。#myArray[ i][j]# -
@user3023588 - 好的,现在您发布了错误消息就更有意义了 ;-) 如果您考虑错误消息确切地说明了问题所在...您使用的是 array 循环 - 这意味着
index将包含数组中元素之一的值。但是,输出代码设计用于 from/to 循环,其中index值是位置或数字,即 1、2、3 等...
标签: arrays multidimensional-array coldfusion cfloop