web页面两个list集合迭代,确定checkbox的checked状态

来源:互联网 发布:lab series知乎 编辑:程序博客网 时间:2024/06/06 01:20

(jstl实现如下:roleList是角色参数列表,内容有NAME和DESCRIPTION;userRoleList存的是一个用户对象的所有角色权限)

<c:forEach items="${roleList}" var="roleList">
    <input type="checkbox" id="roles" name="roles" 
 value="<c:out value='${roleList.NAME}' />" 
 <c:forEach items="${userRoleList}" var="userRoleList">
 <c:if test="${roleList.NAME eq userRoleList.ROLENAME}" >checked</c:if>
 </c:forEach>  />
<c:out value='${roleList.DESCRIPTION}' />
 </c:forEach>





(FreeMarker实现如下:mobilePowerList是参数列表,内容有mobilePowerId和powerName;powerIdList存的是一个对象所有被选中的mobilePowerId的值)

<@ww.iterator value="mobilePowerList" status="rowstatus">
<input type="checkbox" id="mobilePower" name="mobilePower"
value="${mobilePowerId?default('')}"
<@ww.iterator value="powerIdList" id="powerId_" status="rowstatus">
<#if powerId_?number == mobilePowerId?number>checked</#if>
</@ww.iterator>
/>
${powerName?default('')}
</@ww.iterator>


原创粉丝点击