简体   繁体   中英

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

Sample code in 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.

Now someList.value and someList.displayText both the values are the same.

Example:

[iphone,samsung,lenovo,motog,oneplus]    

I want to remove iphone from this.

You can't remove the item in the c:forEach tag but you can use c:if tag to filter 'iphone' from the options.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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