日期:2014-05-18  浏览次数:20626 次

帮帮忙,搞了很久,没排出来。。
List   list=new   ArrayList();
HashMap   rs=new   HashMap();
rs.put( "id ",   new   Integer(1));
rs.put( "name ",   "福建 ");
rs.put( "parent_id ",   new   Integer(0));
list.add(rs);
rs=new   HashMap();
rs.put( "id ",   new   Integer(2));
rs.put( "name ",   "浙江 ");
rs.put( "parent_id ",   new   Integer(0));
list.add(rs);
rs=new   HashMap();
rs.put( "id ",   new   Integer(3));
rs.put( "name ",   "福州 ");
rs.put( "parent_id ",   new   Integer(1));
list.add(rs);
rs=new   HashMap();
rs.put( "id ",   new   Integer(4));
rs.put( "name ",   "厦门 ");
rs.put( "parent_id ",   new   Integer(1));
list.add(rs);
rs=new   HashMap();
rs.put( "id ",   new   Integer(5));
rs.put( "name ",   "鼓楼区 ");
rs.put( "parent_id ",   new   Integer(3));
list.add(rs);
rs=new   HashMap();
rs.put( "id ",   new   Integer(6));
rs.put( "name ",   "台江区 ");
rs.put( "parent_id ",   new   Integer(3));
list.add(rs);
System.out.println(list);
想把这个list输出后成string,组合成一个下拉框。string内容为 <option   value=id> name </option>
可能有很多级。。。。。。。。。。。这是一个地区表

------解决方案--------------------
for(int i=0;i <list.size();i++){
rs = (HashMap)list.get(i);
sb.append( " <option value= ' ");
sb.append(rs.get( "id "));
sb.append( " '> ");
sb.append(rs.get( "name "));
sb.append( " </option> ");
sb.append( "\n ");
}
System.out.println(sb.toString());