简体   繁体   English

如何在迭代时从任何列表对象中删除元素<c:foreach> JSP中选择标签中的标签?

[英]How to remove an element from any list object while iterating through <c:foreach> tag in select tag in JSP?

Sample code in JSP: JSP中的示例代码:

<select> 
  <option value="0">Select</option> 
  <c:forEach items="${list}" var="someList">
    <option value="${someList.value}">${someList.displayText}</option>
  </c:forEach>
</select>

list object coming from Spring controller stored in model object.来自存储在模型对象中的 Spring 控制器的列表对象。

Now someList.value and someList.displayText both the values are the same.现在someList.valuesomeList.displayText这两个值是相同的。

Example:例子:

[iphone,samsung,lenovo,motog,oneplus]    

I want to remove iphone from this.我想从中删除iphone。

You can't remove the item in the c:forEach tag but you can use c:if tag to filter 'iphone' from the options.您不能删除c:forEach标签中的项目,但您可以使用c:if标签从选项中过滤“iphone”。

<select> 
  <option value="0">Select</option> 
  <c:forEach items="${list}" var="someList"> 
   <c:if test="${someList.value != 'iphone'}">   
    <option value="${someList.value}">${someList.displayText}</option>  
   </c:if>
  </c:forEach> 
</select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM