Arrays 如何在数组中找到空元素?
我有一堆问题和答案,未回答的问题必须在顶部抛出并显示错误消息,答案在数组中,如果未回答,数组将值存储为未定义的数组元素 我试图通过将元素转换为list来检索元素的位置,但在循环时,list丢失了空元素。当我使用简单循环进行循环时:Arrays 如何在数组中找到空元素?,arrays,coldfusion,null,Arrays,Coldfusion,Null,我有一堆问题和答案,未回答的问题必须在顶部抛出并显示错误消息,答案在数组中,如果未回答,数组将值存储为未定义的数组元素 我试图通过将元素转换为list来检索元素的位置,但在循环时,list丢失了空元素。当我使用简单循环进行循环时: <cfloop from ="1" to="#arraylen(currentinfo.answers)#" index="ele"> <cfset i = i+1> <cfif not listlen(currentinf
<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>
#j#
我得到以下错误:
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>
元素5在类型为coldfusion.runtime.Array的Java对象中未定义。
错误出现在D:\sites\askseaton\sections\PSSurvey\Clients\tags\surveydisplay.cfm:第194行
192 :
193 :
194:#j#
195 :
196:必须回答问题j才能继续。
自ColdFusion 8以来,有一个函数可以执行您想要执行的操作。或者尝试在阵列上循环的替代方法:
<cfloop array="#currentinfo.answers#" index="ele">
<cfset i++>
<cfif not listlen(ele,'-')><cfset j=i>#j#</cfif>
</cfloop>
#j#
能否尝试arraySort?listLen()忽略空列表元素。仅包含内容计数的元素。