[英]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.value
和someList.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.