Display hashmap values in HTML dropdown box [closed]

青春壹個敷衍的年華 提交于 2019-12-23 04:26:51

问题


How to display hashmap values in an HTML dropdown box using Java?

HashMap<Integer,String> hm =new HashMap<Integer,String>();
hm.put(1,"abc");
hm.put(2,"def");
hm.put(3,"ghi");

Using the jEasyUI framework with jQuery.


回答1:


<%
    HashMap<Integer,String> hm =new HashMap<Integer,String>();
    hm.put(1,"abc");
    hm.put(2,"def");
    hm.put(3,"ghi");

     for(int i=1;i<hm.size();i++){
%>
      <option value="<%= i%>"><%= hm.get(i) %></option>
<% } %>



回答2:


You can use list returned from hm.values()




回答3:


Take a for loop and build options like below

"<option value="+hm.getKey()+">"+hm.getValue()+"</option>";

HashMap doc.



来源:https://stackoverflow.com/questions/22912859/display-hashmap-values-in-html-dropdown-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!