前端页面上轮播最多展示6条数据,2个数据分成一组,一共展示3组。每组的数据需要放在li标签里,如下所示:
- 数据1数据2
- 数据3数据4
- 数据3数据4
直接遍历数据,是没有办法实现的,但是可以再遍历数据时,根据数据的顺序,将其放入到li标签中。
1.顺序为奇数时:遍历数据前加入
2.顺序为偶数时:遍历数据后加入
3.当遍历到最后一条数据,如果为奇数,加入标签。
使用freeMarker渲染的代码如下:
<#list studioInfos as studioInfo><#if studioInfo_index % 2 == 0>#if>数据体<#if studioInfo_index % 2 == 1 || (studioInfo_index % 2 == 0 && studioInfo_index+1 == studioInfos?size)> #if>
#list>