当outputdata列表为空时,简化默认显示一行

bum*_*paw 8 jsp jstl el

<table>
<c:if test="${output.list == nul}">
<tr><td><input type="text" /><select></select><input type="text" />
</td>
</tr>
</c:if>
<c:forEach var="iter" items="${output.list}">
<tr><td><input type="text" /><select></select><input type="text" value="${iter.getVal()}" />
</td>
</tr>
</c:forEach>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

如果我${list}是空的,如何在.clone不重复代码或使用javascript的情况下显示行?

Ken*_*kov 2

不知道我是否理解了你的问题。如果您想输出一行包含所有内容,当列表为空时,请尝试下一种方法:

  <table>
        <c:forEach var="i" begin="0" end="${not empty list?(fn:length(list)-1):0}">
          <tr class="clone">
            <td>
               <input type="text" />
               <select></select>
               <input type="text" value="${list[i]!=null?list[i].getVal():''}" />
            </td>
          </tr>
        </c:forEach>
 </tbody>
Run Code Online (Sandbox Code Playgroud)

要使用fn:命名空间,只需在文件开头添加<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

更新:根据问题的变化而改变