3

所以我有这个代码:

<!-- New Array for my loop -->
<cfset filesArray = ArrayNew(1)>
<!-- index for loop -->
<cfset arrayIndex = 1>

<!-- When a user attaches a file jQuery attaches a
hidden input element to the DOM with an id of 'attachedFile(index)'
and a value of the file name. This loops over the form fields looking for input with
id of 'attachedFile(something)' and sticks it into my array-->
<cfloop collection="#FORM#" item="field">
    <cfif FindNoCase('attachedFile',field) IS 1>
        <cfset filesArray[arrayIndex] = field>
        <cfoutput>#filesArray[arrayIndex]#<br></cfoutput>
        <cfset arrayIndex = arrayIndex + 1>
    </cfif>
</cfloop>

<!-- I use this to sort my array, it outputs YES
so I know it works right up until here -->
<cfoutput>#ArraySort(filesArray,'text','asc')#</cfoutput>

<!-- Simple loop over my array so I can output what I'm creating, but I get an error
"ATTACHEDFILE1 cannot be converted to a number' -->
<cfloop array=#filesArray# index="i">
    <cfoutput>#filesArray[i]#</cfoutput>
</cfloop>

我不知道我在哪里尝试将索引 i 处的数组转换为数字,但这是我的全部代码。有人看到问题了吗?数组最后应该输出没问题,对吗?

4

1 回答 1

5

与数组一起使用时, index in<cfloop>不是数字。它实际上是数组中的元素。

我知道,措辞没有意义,但请检查文档。

于 2012-08-08T19:55:29.243 回答