s:iterator标签迭代与<tr><td>的结合使用,一行2条或一行多条显示方法

一个jsp页面,从后台获得集合,在页面用s:iterator遍历集合,一行显示3条。格式如下:


1    2   3

4    5   6

7    8    9

用法如下

<table>
					<s:iterator value="smallBoards" status="count">
					
						  <s:if test="#count.index%3==0||#count.first">        
            <tr>            
        </s:if> 
						<td><a href="#"><s:property value="name" /></a></td>
					</s:iterator>
					 <s:if test="#count.index%2!=0||#count.last">        
            </tr>            
        </s:if> 
			</table>

这里用count.index来获取下标,一行显示三条数据的格式为 

<s:if test="#count.index%X==0||#count.first">   <tr>     </s:if> 

<s:if test="#count.index%X-1!=0||#count.first">   <tr>     </s:if> 

X为一行显示个数

注释:

int getCount(); 迭代元素个数
int getIndex(); 迭代元素当前索引
boolean isEven() 当前迭代元素索引是否为偶数; 
boolean isOdd() 当前迭代元素索引是否为奇数; 
boolean isLast() 是否为最后一条元素; 
boolean isFirst() 是否为第一条元素。 


不懂可以留言。


猜你喜欢

转载自blog.csdn.net/ck784101777/article/details/80769943