使用 CFSEARCH,我将键变量包含为逗号分隔列表,以返回比四个自定义字段允许的更多信息。但是,系统抛出一个错误,指出无法找到列表项。
“key”变量的每条记录将具有以下格式:a,b,c
<cfsearch
name="theCourses"
collection="#arguments.collectionName#"
type="simple"
startrow="1"
maxrows="100"
criteria="#Lcase(Trim(arguments.searchCriteria))#"
contexthighlightbegin="<b>"
contexthighlightend="</b>"
status="courseListStatus"
/>
<cfset courseList = QueryNew("ID, Score, Course, Subject, Day, Title, Semester, Status", "varchar, varchar, varchar, varchar, varchar, varchar, varchar, varchar") />
<cfloop query="theCourses">
<cfset temp = QueryAddRow(courseList) />
<cfset temp = QuerySetCell(courseList, "ID", custom3) />
<cfset temp = QuerySetCell(courseList, "Score", score) />
<cfset temp = QuerySetCell(courseList, "Course", ListGetAt(key, 2, ",")) />
<cfset temp = QuerySetCell(courseList, "Subject", ListFirst(key, ",")) />
<cfset temp = QuerySetCell(courseList, "Day", custom1) />
<cfset temp = QuerySetCell(courseList, "Title", custom4) />
<cfset temp = QuerySetCell(courseList, "Semester", custom2) />
<cfset temp = QuerySetCell(courseList, "Status", ListLast(key, ",")) />
</cfloop>
我收到以下错误:
无效的列表索引 2。
在函数 ListGetAt(list, index [, delimiters]) 中,index 的值 2 作为第一个参数无效(此列表有 1 个元素)。有效索引的范围是 1 到列表中的元素数。