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