我正在使用cfloop中的大量项目。我想减少它并加入分页。在我的cfloop中有没有将数组限制在前10个?
我有
<cfloop array="#qryItems#" index="index">
我试过把它变成一个没有运气和其他一些东西的条件循环。我有一段时间没有接触过冷敷,而且有点生锈。谷歌没有帮助哈哈
我试过了
<cfloop from="1" to="10" array="#qryItems#" index="index">
并且还尝试过max_rows
<cfloop maxrows="10" array="#qryItems#" index="index">
每次收到错误消息
&#34;标签CFLOOP的属性验证错误。&#34;
答案 0 :(得分:2)
<cfloop from="1" to="10" index="index">
<!--- Then do your business with array elements qryItems[index], that is, with qryItems[1], qryItems[2],..., qryItems[10] --->
</cfloop>
答案 1 :(得分:1)
cfloop
没有属性组合来实现您的期望。正如BKBK建议的那样,您需要使用from/to
循环来输出一组选定的记录。如果我正确理解了您的要求,我也会使用新的索引变量更新您的cfloop
,然后通过引用数组元素来设置旧变量。
下面的两个cfloops
输出相同的数据,第二个只显示分页范围内的记录。
<cfset qryItems = [1,2,3,4,5,6,7,8,9,10,'a','b','c','d'] />
<cfoutput>
<!--- Current loop: Outputs all records --->
<cfloop array="#qryItems#" index="index">
#index#
</cfloop>
<cfset paginationStart = 1 />
<cfset paginationEnd = 10 />
<!--- Only the range of of records requested --->
<cfloop from="#paginationStart#" to="#paginationEnd#" index="indexNumber">
<cfset index = qryItems[indexNumber] />
<!--- code remain the same --->
#index#
</cfloop>
</cfoutput>