我试图调用 hasNext
Velocity 模板中的方法,以便根据 foreach 循环中的位置影响行为 - 仅 hasNext
没有按照文档工作。
这是 Velocity 用户指南的片段,关于 hasNext
的使用:
Velocity also now provides an easy way to tell if you are on the last iteration of a loop:
#foreach( $customer in $customerList )
$customer.Name#if( $foreach.hasNext ),#end
#end
这是我的版本:
#foreach ($nav_item in $priNavItems)
...
#if ( $foreach.hasNext )
<img alt="" class="dive" src="/olp-theme/images/custom/dive.png">
#end
#end
有没有人成功地在
#foreach
中调用此方法?在速度模板中循环?也许使用不同的名称(例如 $velocityCount
用于计数)?任何/所有建议和/或方向表示赞赏 - 谢谢!
最佳答案
Velocity 1.6.3 不支持此功能; $foreach.hasNext
功能由 ForeachScope
提供类 1.7+ ( docs )。
在线文档是指当前版本;使用早期版本时,您需要引用该特定版本的文档。
关于速度 hasNext 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7796653/