gpt4 book ai didi

java - JSTL 检查数组中的值是否与第二个数组匹配

转载 作者:行者123 更新时间:2023-12-02 00:27:23 24 4
gpt4 key购买 nike

又是我。基本上,我会在用户点击页面后检查他们的角色。它是一个数组,比方说 1,2,3。用于测试的 jsp 上最后一列的内容具有附加到每个单独附件的角色 #。最后一列不会出现在成品上,但我需要对该数组执行某种 IF 来查看数组中是否有任何值:

<c:forEach items = "${hotPartRoles}" var = "hpRole"> 
${hpRole.id}
</c:forEach>

在附件角色数组中:

<c:forEach items = "${item.roles}" var = "role"> 
${role.id}
</c:forEach>

jsp:

<table class="data_table">
<tr>
<th>Attachments</th>
//These are the user's Roles
<c:forEach items = "${hotPartRoles}" var = "hpRole">
${hpRole.id}
</c:forEach>

</tr>
<tr>
<td class="subtable">
<table class="data_table">
<c:choose>
<c:when test='${empty attachList}'>
<tr>
<td>No Attachments</td>
</tr>
</c:when>
<c:otherwise>
<tr>
<th>Remove Attachment</th>
<th>File Name</th>
<th>File Type</th>
<th>File Size (bytes)</th>
<th>File Attached By</th>
<th>Date/Time File Attached</th>
<th>Roles</th>
</tr>
<c:forEach var="item" items="${attachList}" varStatus="loopCount">
<tr>

<td class="button">
<rbac:check operation="<%=Operation.DELETE%>">
<button type="button" onclick="javascript:delete_prompt(${item.id});">Delete</button>
</rbac:check>
</td>
<td><a href="show.view_hotpart_attachment?id=${item.id}">${item.fileName}</a></td>
<td>${item.fileType}</td>
<td><fmt:formatNumber value="${item.fileSize}" /></td>
<td>${item.auditable.createdBy.lastName}, ${item.auditable.createdBy.firstName}</td>
<td><fmt:formatDate value="${item.auditable.createdDate}" pattern="${date_time_pattern}" /></td>
<td>
<c:forEach items = "${item.roles}" var = "role">
${role.id}
</c:forEach>
</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>

现在数组不需要完全匹配,只是用户角色数组中的值位于附件角色数组中......

我需要在这里进行检查以确定是否在“删除”按钮上放置禁用标志:

 <rbac:check operation="<%=Operation.DELETE%>">
<button type="button" onclick="javascript:delete_prompt(${item.id});">Delete</button>
</rbac:check>
</td>
<td>

最佳答案

执行 2 个嵌套 for 循环并将 var 最初设置为 false,然后设置为 true 并检查该 var 似乎有效

   <c:forEach var="item" items="${attachList}" varStatus="loopCount">
<c:set var="dispVal" value="false"/>
<c:forEach items = "${item.roles}" var = "role">
<c:forEach items = "${hotPartRoles}" var = "hpRole">
<c:if test="${hpRole.id == role.id}">
<c:set var="dispVal" value="true"/>
</c:if>
</c:forEach>
</c:forEach>

<tr>

<td class="button">
<rbac:check operation="<%=Operation.DELETE%>">

<button type="button"<c:if test="${dispVal != 'true'}"> disabled="disabled"</c:if>
onclick="javascript:delete_prompt(${item.id});">Delete</button>

关于java - JSTL 检查数组中的值是否与第二个数组匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9737986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com