首页 > 解决方案 > Struts 1.3 为表中的特殊属性迭代一次

问题描述

我的 .jsp 文件中有一个 tbody:

    <tbody>
        <logic:iterate name="tableList" property="list" id="e">
            <tr class="text-center">
                <td class="text-center"><bean:write name="e" property="A" /></td>
                <td class="text-center"><bean:write name="e" property="B" /></td>
                <td class="text-center"><bean:write name="e" property="C" /></td>
            </tr>
        </logic:iterate>
    </tbody>

我只想迭代我的属性“A”一次,但“B”和“C”正常迭代。有什么办法吗?

我尝试在 java 类中验证它,当我的 A 属性只有一项时,我使用了行跨度,但是当我想:

<td rowspan="12" class="text-center"><bean:write name="e" property="A" /></td>

它也不能工作(整张桌子都被破坏了)。

标签: strutsstruts-1

解决方案


您可以在 indexId 属性上使用计数器并使用 logic:equal 或 jstl c:if 进行测试,如下所示:

<c:if test="${condition}"> condition is true </c:if>

代码下方

<tbody>
    <logic:iterate name="tableList" property="list"  indexId="ctr" id="e">
        <tr class="text-center">

            <logic:equal name="ctr" value="0" >
                <td class="text-center"><bean:write name="e" property="A" /></td>
            </logic:equal>
            <td class="text-center"><bean:write name="e" property="B" /></td>
            <td class="text-center"><bean:write name="e" property="C" /></td>
        </tr>
    </logic:iterate>


推荐阅读