首頁  >  文章  >  後端開發  >  velocity第五個應用範例---取得目前迭代的索引

velocity第五個應用範例---取得目前迭代的索引

黄舟
黄舟原創
2017-01-17 10:54:461828瀏覽

velocity第五個應用範例---取得目前迭代的索引

#foreach($key in $map.keySet())

$velocityCount > $key : $map.get($key)

#end

$velocityCount获得当前迭代索引

velocityCount变量名可以通过directive.foreach.counter.name属性修改,

如:directive.foreach.counter.name=index,以后可以通过$index进行访问。

迭代的索引默认从1开始,我们可以通过directive.foreach.inital.value=0进行修改。

控台輸出

1> key4 : value4

2> key3 : value3

3> key2 : value2

4> key1 : value1

修改索引變數名稱

在屬性檔增加配置範本

#修改索引变量名

directive.foreach.counter.name=index

index.vm



#foreach($key in $map.keySet())

$index 
>>> 
$key : $map.get($key)

#end



#修改迭代索引的默认值


directive.foreach.counter.initial.value=0

模板

#foreach($key in $map.keySet())

$index 
>>> 
$key : $map.get($key)

#end

以上就是velocity第五個應用範例---獲得當前迭代的索引的內容,更多相關內容請關注PHP中文網(www.php.cn)!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn