我有一个 Hashmap 对象allList
,其形式为 type HashMap<String,ArrayList<Item>>
。我想将它的 JSP 页面显示为jquery 手风琴。下面是我尝试过的代码。
<script type="text/javascript">
$(function() {
$( "#accordion" ).accordion({
heightStyle: "fill",
collapsible: true
});
});
</script>
<div id="accordion">
<c:forEach items="${allList}" var="myLs">
<h3>${myLs.key}</h3>
<div>${myLs.value}</div> // This is giving me toString of Item.
</c:forEach>
</div>
我能够将哈希图的键显示为标题。但我无法弄清楚如何将相应的 arraylist 对象显示为有序列表。请帮帮我。
public class Item implements java.io.Serializable, Comparable<Object> {
private Long id;
private String itemName;
private Double unitCost;
private String status;
private int quantity;
public Item() {
}
//getters and setters
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Item)) {
return false;
}
final Item item = (Item) o;
if (getItemName() != null && item.getItemName() == null)
return false;
if (getItemName() == null && item.getItemName() != null)
return false;
if (!getItemName().equals(item.getItemName()))
return false;
return true;
}
public int hashCode() {
return getItemName().hashCode();
}
public String toString() {
return "Item - Id: "+getId+", Name : "+getItemName;
}
public int compareTo(Object o) {
if (o instanceof Item) {
return getItemName().compareTo(((Item) o).getItemName());
}
return 0;
}
}