如何使用struts2在两个div中安排来自arraylist的数据 [英] How arrange data from an arraylist in two divs using struts2
问题描述
我在ArayList中有一组图像。我试图按行排列这些图像,每行包含4个图像。因此,如果arraylist中有10个图像,则应该有3行,其中第一行为4,第二行为4,第三行为2。
I have a set of images in an ArayList. I am trying to arrange these images in rows, with each row containing 4 images. So if there are 10 images in the arraylist, there should be 3 rows with 4 in first, 4 in second and 2 in third row.
这是我的jsp。
<s:iterator value="productList" status="status">
<div class="display">
<div class="block">
<img src="../product/image?imageID=<s:property value="productID"/>&type=thumbnail" />
</div>
</div>
</s:iterator>
这里带有类显示的div充当行。带有类块的
div作为显示div内的列。
Here div with class display acts as the rows. div with the class block acts as the columns inside the display div.
怎么做?任何帮助将不胜感激
How can it be done? Any help will be appreciated
推荐答案
我能想到两种方法..
1.表(最简单)
2. ul li
There are two approachs that i can think of.. 1. Table(easiest) 2. ul li
在表格中,代码看起来像
In the table approach the code will look something like
<table>
<s:iterator value="productList" status="status">
<s:if test="#status.index %4 == 0">
<tr>
</s:if>
<td>
<img src="../product/image?imageID=<s:property value="productID"/>&type=thumbnail" />
</td>
<s:if test="#status.index %4 == 0">
</tr>
</s:if>
</s:iterator>
<table>
如果标签必须关闭,你可能还需要在迭代器之后检查
Also you might want to check after the iterator if the tag has to be closed
这篇关于如何使用struts2在两个div中安排来自arraylist的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!