jsp下拉框select中options遍历集合

xiaoxiao2021-02-27  137

第一种方式:使用options

<form:options items="后台传过来的集合" itemLabel="取集合中的某个属性进行显示" itemValue="将遍历的值赋值给某个属性" htmlEscape="设置是否启用默认html字符转换,填true或者false"/>

注意:用options遍历集合时,不需要c:forEach标签进行循环

eg:

<form:select path="number" class="input-xlarge required"> <form:options items="${t}" itemLabel="number" itemValue="number" htmlEscape="false"/> </form:select> //path="number" ,要为某个属性赋值

第二种方式:使用option+forEach

<c:forEach items="后台传过来的要遍历的集合" var="遍历的变量名"> <form:option value="将遍历的值赋值给某个属性" label="取变量的某个属性进行显示"/> </c:forEach>

eg:

<form:select path="number" class="input-xlarge required"> <c:forEach items="${t}" var="teacher"> <form:option value="number" label="${teacher.number}"/> </c:forEach> </form:select>
转载请注明原文地址: https://www.6miu.com/read-14704.html

最新回复(0)