1

我有一堆问题和答案,未回答的问题必须在顶部抛出错误消息,答案在数组中,如果未回答,则数组将值存储为未定义的数组元素。

我试图通过将元素转换为列表来检索元素的位置,但是在循环列表时丢失了空元素。当我用简单的循环循环它时:

  <cfloop from ="1" to="#arraylen(currentinfo.answers)#" index="ele">
  <cfset i = i+1>
   <cfif not listlen(currentinfo.answers[ele],'-')><cfset j=#i#>#j#</cfif>
  </cfloop>

我在下面收到错误:

Element 5 is undefined in a Java object of type class coldfusion.runtime.Array.  

The error occurred in D:\sites\askseaton\sections\PSSurvey\Clients\tags\surveydisplay.cfm: line 194

192 : <cfloop from ="1" to="#arraylen(currentinfo.answers)#" index="ele">
193 : <cfset i = i+1>
194 :   <cfif not listlen(currentinfo.answers[ele],'-')><cfset j=#i#>#j#</cfif>
195 : </cfloop>
196 : <div>Question(s)#j# must be answered to proceed further.</div>
4

2 回答 2

2

从 ColdFusion 8 开始,就有一个arrayIsDefined()功能可以做你想做的事情。

于 2012-11-06T16:30:32.930 回答
0

或者尝试循环遍历数组的另一种方法:

 <cfloop array="#currentinfo.answers#" index="ele">
  <cfset i++>
   <cfif not listlen(ele,'-')><cfset j=i>#j#</cfif>
  </cfloop>
于 2012-11-06T16:48:46.267 回答