Display hashmap values in HTML dropdown box [close

2019-06-02 02:14发布

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.

3条回答
够拽才男人
2楼-- · 2019-06-02 02:22

You can use list returned from hm.values()

查看更多
爷、活的狠高调
3楼-- · 2019-06-02 02:28

Take a for loop and build options like below

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

HashMap doc.

查看更多
神经病院院长
4楼-- · 2019-06-02 02:30
<%
    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>
<% } %>
查看更多
登录 后发表回答