论坛首页 Java企业应用论坛

在 <#list>中实现动态换行

浏览 6869 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (5)
作者 正文
   发表时间:2009-02-02   最后修改:2009-02-03

1.代码

<table width="100%" height="0%" border="0">
    <tr align="center" valign="middle">
        <td height="46%" colspan="6" class="td_head">

           <B>角色名称&nbsp;</B>
        </td>
    </tr>
    <tr>
        <#list roles as role>
            <td nowrap align='right' colspan='1' rowspan='1' height='25'>

               <!--  被选择的 checkbox -->
              
<#list bean.roles as userRole>

                   <!-- 不加此句 <#assign checked="checked"> 被执行后 checked的值将一直为"checked" -->  
                   <#assign checked="">  

                   <#if role.id==userRole.id>
                        <#assign checked="checked">
                        <#break/>
                   </#if>
               </#list> 
               

            <input name="roleid" type="checkbox" userid="roleid" value="${role.id!}" ${checked!}>
            </td>
            <td nowrap align='left' colspan='1' rowspan='1' height='25'>
                ${role.rolename!}
            </td>

            <!--  每显示三个对象换一行  -->
            <#if (role_index != 0 && role_index % 2 == 0)>
               </tr>
               <tr>
            </#if>

        </#list>
    </tr>
</table>

 

2.例图



 

 

 

  • 大小: 50.7 KB
   发表时间:2009-02-03  
以前弄过一个换行,比较笨的方法,楼主看行不(主要是拼凑tr td)

<table class="table-form" style="width:100%;text-align:center" cellspacing="2" cellpadding="1">
            <tr>
                <td>年份</td>
                <td width="246" class="four-content">
                    <select name="year" class="common-select">
                    </select>
                </td>
                <td colspan="2"></td>
            </tr>
            <tr>
                <td>起始月份</td>
                <td width="246" class="four-content">
                    <select name="startMonth" class="common-select">
                        <#if (monthList)?exists&&monthList.size()!=0>
                            <#list monthList as month>
                                <option value=${(month)?default('')}>${(month)?default('')}</option>
                            </#list>
                        </#if>
                    </select>
                </td>
                <td>终止月份</td>
                <td width="246" class="four-content">
                    <select name="endMonth" class="common-select">
                        <#if (monthList)?exists&&monthList.size()!=0>
                            <#list monthList as month>
                                <option value=${(month)?default('')}>${(month)?default('')}</option>
                            </#list>
                        </#if>
                    </select>
                </td>
            </tr>
            <tr>
                <td>机关</td>
                <td class="two-content" colspan="3" width="100%">
                    <div style="width:100%">
                        <#if (orgList)?exists&&orgList.size()!=0>
                            <table>
                                <#list orgList as area>
                                    <#if (area_index)%4==0>
                                        <tr>
                                    </#if>
                                    <td style="text-align:left">
                                        <input name="orgCode" type="checkbox" style="width:18px;"
                                               nameCoyp="${(area.areaName)?default('')}"
                                               value="${(area.areaCode)?default('')}">${(area.areaName)?default('')}
                                    </td>
                                    <#if (area_index)%4==3>
                                        <tr>
                                    </#if>
                                </#list>
                            </table>
                        </#if>
                    </div>
                    <br>
                    <table>
                        <tr>
                            <td style="width:26%;text-align:left"><input type="checkbox" name="control"
                                                                         style="width:18px;" value="true"
                                                                         onclick="setSelectAll(this)">全选
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
0 请登录后投票
   发表时间:2009-02-03  
对于这种将某个集合分隔为N,然后进行遍历的需求,你可以使用freemarker提供的chunk:
<#list seq?chunk(3) as row>
  <tr>
    <#list row as cell><td>${cell}</td></#list>
  </tr>
</#list>


不过这样使用tr/td进行换行排版,是不被推荐的,你完全可以采用CSS指定每个选择框的长度为1/3,设置float/block就可以了
0 请登录后投票
   发表时间:2009-02-03  
Quake Wang 写道

对于这种将某个集合分隔为N,然后进行遍历的需求,你可以使用freemarker提供的chunk:


Freemarker代码

&lt;#list&nbsp;seq?chunk(3)&nbsp;as&nbsp;row&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&lt;tr&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;#list&nbsp;row&nbsp;as&nbsp;cell&gt;&lt;td&gt;${cell}&lt;/td&gt;&lt;/#list&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&lt;/tr&gt; &nbsp;&nbsp;
&lt;/#list&gt;&nbsp;&nbsp;&lt;#list seq?chunk(3) as row&gt;
  &lt;tr&gt;
    &lt;#list row as cell&gt;&lt;td&gt;${cell}&lt;/td&gt;&lt;/#list&gt;
  &lt;/tr&gt;
&lt;/#list&gt;
不过这样使用tr/td进行换行排版,是不被推荐的,你完全可以采用CSS指定每个选择框的长度为1/3,设置float/block就可以了


学习了,谢谢
0 请登录后投票
   发表时间:2009-04-15  
QuakeWang 写道
对于这种将某个集合分隔为N,然后进行遍历的需求,你可以使用freemarker提供的chunk:
<#list seq?chunk(3) as row>
  <tr>
    <#list row as cell><td>${cell}</td></#list>
  </tr>
</#list>


不过这样使用tr/td进行换行排版,是不被推荐的,你完全可以采用CSS指定每个选择框的长度为1/3,设置float/block就可以了

此楼正解.
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics