thymeleaf 之 th:each

<span  th:each="cartInfo,stat:${checkedCartList}">
				<input name="orderDetailList[0].skuId'" type="hidden"    value="" />
				<input name="orderDetailList[0].skuNum'" type="hidden"    value="" />
				<input name="orderDetailList[0].orderPrice'" type="hidden"    value="" />
</span>

想要在html的循環中獲取角標,引入thymeleaf 之 th:each狀態變量,即stat

     index:當前迭代對象的index(從0開始計算)
    count: 當前迭代對象的index(從1開始計算)
    size:被迭代對象的大小
    current:當前迭代變量
    even/odd:布爾值,當前循環是否是偶數/奇數(從0開始計算)
    first:布爾值,當前循環是否是第一個
    last:布爾值,當前循環是否是最後一個

例如:

                <th th:text="${Stat.index}">狀態變量:index</th>
		        <th th:text="${Stat.count}">狀態變量:count</th>
		        <th th:text="${Stat.size}">狀態變量:size</th>
		        <th th:text="${Stat.current.userName}">狀態變量:current</th>
		        <th th:text="${Stat.even}">狀態變量:even****</th>
		        <th th:text="${Stat.odd}">狀態變量:odd</th>
		        <th th:text="${Stat.first}">狀態變量:first</th>
		        <th th:text="${Stat.last}">狀態變量:last</th>

所以:

<span  th:each="cartInfo,stat:${checkedCartList}">
				<input th:name="'orderDetailList['+${stat.index}+'].skuId'" type="hidden"  value="" />
				<input th:name="'orderDetailList['+${stat.index}+'].skuNum'" type="hidden"  value="" />
				<input th:name="'orderDetailList['+${stat.index}+'].orderPrice'" type="hidden"  value="" />
</span>

 

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章