动态checkbox 问题

liuc0317 liuc0317 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我现在做的一个东西需要在做更新的时候把从数据库取出的checkbox选中。
从数据库取出的是一个cIndustrys.(当前行业)
页面中把所有的checkbox都列出(行业)。如果条件相同就checked="checked"
问题:当所把所有的行业都列出,(所有行业 industrys)行业 父类 和子类,当前行业是包括父子类的。
怎么选中:
代码如下:但会输出两次

<c:forEach items="${cIndustrys}" var="cIndustry">
<c:set value="false" var="isEmpty"></c:set>
<c:set value="false" var="isEmpty2"></c:set>
<c:forEach items="${industrys}" var="industry">
<c:choose>
<c:when test="${cIndustry.industryId==industry.industryId}">
<input type="checkbox" class="check" checked="checked" name="industry" value="${industry.industryId}">${industry.industryCnName}</br>
</c:when>
<c:otherwise>
<input type="checkbox" class="check" name="industry" value="${industry.industryId}">${industry.industryCnName}</br>
</c:otherwise>
</c:choose>
<c:forEach items="${industry.subIndustries}" var="sub">
<c:choose>
<c:when test="${cIndustry.industryId==sub.industryId}">
    <input type="checkbox" class="check" checked="checked" name="industry" value="${sub.industryId}">${sub.industryCnName}</br>
</c:when>
<c:otherwise>
    <input type="checkbox" class="check" name="industry" value="${sub.industryId}">${sub.industryCnName}</br>
</c:otherwise>
</c:choose>

</c:forEach>

</c:forEach>

</c:forEach>
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
liuc0317
Web 开发 81,108 成员 341,721 内容