在自由标记列表中设置开始索引

Set begin index in freemarker list

如何在freemarker列表中设置开始索引?

喜欢jstl

<c:forEach var="item" items="${screenshot.results}" begin="2">
    <a href="${item.image}"
       class="fresco"
       data-fresco-group="game-detail-pic">
    </a>
</c:forEach>

我想从第二个索引开始。

您可以使用 sequence 内置

applying the sequence built-in allows all sequence operations, such as seq[index], seq[range], or seq?size. If these operations are directly applied on a sequence that was converted from a collection, then FreeMarker optimizes out actually creating the sequence in memory. So these won't consume much memory regardless of the size of the filtered hugeTable:

hugeTable?filter(predicate)?sequence[index]: FreeMarker will just fetch and drop the elements till it reaches the element at the desired position.

hugeTable?filter(predicate)?sequence[0..9]: FreeMarker will just collect the first 10 elements.

示例:

<#assign a=[1,2,3,5,6]>
<#list a?filter(x ->  x > 0)?sequence[1..4] as x>${x} </#list>