Apache 如何在速度上将一个序列拆分为多个序列?
我有这个阵列:Apache 如何在速度上将一个序列拆分为多个序列?,apache,foreach,velocity,Apache,Foreach,Velocity,我有这个阵列: seq = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] 我想把这个序列分成两个有四个元素的序列,如下所示: a b c d e f g h 我尝试使用两个foreach来拆分列表,一个用于对四个元素进行分组,另一个用于获取元素。但它不起作用: #foreach( $groupOfFour in $allProducts ) #if( $velocityCount == 4 ) <ul&g
seq = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
我想把这个序列分成两个有四个元素的序列,如下所示:
a b c d
e f g h
我尝试使用两个foreach来拆分列表,一个用于对四个元素进行分组,另一个用于获取元素。但它不起作用:
#foreach( $groupOfFour in $allProducts )
#if( $velocityCount == 4 )
<ul>
#foreach( $product in $groupOfFour )
<ul>
<li>$product</li>
</ul>
</ul>
#end
#end
#foreach($allProducts中的groupofffour)
#如果($velocityCount==4)
#foreach($GroupOffFour中的产品)
- $product
#结束
#结束
这看起来非常接近
在Velocity 1.7+中,使用$foreach.index(基于0)、$foreach.count(基于1)、$foreach.first和$foreach.last()
#foreach($product中的$allProducts)
#如果($foreach.index%4==0)
#如果(!$foreach.first)
#结束
#结束
$product
#如果($foreach.last)
#结束
#结束
<ul>
#foreach( $product in $allProducts )
#if( $foreach.index %4 == 0 )
#if( !$foreach.first )
</ul>
#end
<ul>
#end
$product
#if( $foreach.last )
</ul>
#end
#end
</ul>