简体   繁体   English

如何仅显示选定的项目列表?

[英]How to display only selected list of items?

I am trying to populate a list something like below:我正在尝试填充如下所示的列表:

<select name="prescription"  multiple="multiple">
    <c:forEach items="${medicines}" var="current">
        <option value="${current}"><c:out value="${current}" /></option>
    </c:forEach>

</select>

I am trying to populate only the selected list in another similar for each loop.我试图在每个循环的另一个类似中只填充选定的列表。 But i am not getting how to do it.但我不知道该怎么做。 Can any one help me with it?任何人都可以帮助我吗?

Seems like you are showing some list from the controller to the jsp page , You can proceed with either of these 2 ways似乎您正在显示从控制器到 jsp 页面的一些列表,您可以使用这两种方式之一

  1. Add the only items in the list that you want to show for example :添加列表中要显示的唯一项目,例如:

assuming that the list medicine has all the parameters假设列表药物具有所有参数

        List<String> medicine = Your-List;

        List<String> final_medicine = new ArrayList<String>();

    for(int i=0; i < medicine.size(); i++)
    {

              if(your-condition-here){

                  final_medicine.add(medicine.get(i));
             }
    }

request.setAttribute("medicine",final_medicine);

The second way could be getting the values in the jsp itself using the第二种方法可能是使用

<select name="prescription"  multiple="multiple">
    <c:forEach items="${medicines}" var="current">
            <c:if test="${medicines eq your-condition}>
               <option value="${current}"><c:out value="${current}" /></option>
            </c:if>
    </c:forEach>

</select>

If this is something that you require?如果这是您需要的东西?

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

相关问题 在列表中显示所选项目 - Display selected items in a list 如何使用Javascript筛选无序列表以仅显示所选项目? - How do I filter an unorderded list to display only selected items using Javascript? 当只有用户选择该特定复选框时,如何将 jquery 复选框列表的选定项目与标签一起显示 - How to display the selected items of jquery checkbox list along with the label when only the user selects that particular checkbox 仅显示选择的项目-用JavaScript替换innerHTML - Display only items selected - Javascript replacing innerHTML 仅显示列表jQuery中的选定项目 - Show selected items only from a list jquery 如何在新页面中显示所选项目? - How to display the selected items in the new page? 如何在 ReactJS 中显示 treeview 的选中项? - How to display the selected items of a treeview in ReactJS? 使用javascript在listview中仅显示某些列表项 - Display only certain list items in listview with javascript 选择后如何在菜单中显示所选项目? - How to display selected items in the menu as well, after they have been selected? 如何仅在 Angular 应用程序中的项目列表中的选定项目上更改过滤器图标状态? - How can I change a filter icon status only on the selected item of a list of items in my Angular application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM