1

我正在使用 cfloop 中的大量项目。我想减少它并添加分页。在我的 cfloop 中是否有将数组限制为前 10 个?

我有

<cfloop array="#qryItems#" index="index">

我试过把它变成一个条件循环,没有运气和其他一些东西。好久没碰coldfusion了,有点生疏了。谷歌没有帮助哈哈

我努力了

<cfloop from="1" to="10" array="#qryItems#" index="index">

并且还尝试了 max_rows

 <cfloop maxrows="10" array="#qryItems#" index="index">

每次我收到错误信息

“标签 CFLOOP 的属性验证错误。”

4

2 回答 2

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>
于 2016-12-27T19:23:40.630 回答
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>
于 2016-12-27T22:06:06.387 回答