如何将 Map<Key,Object> 传递给 Wicket 中的 ListView?
How to pass a Map<Key,Object> to a ListView in Wicket?
我有以下地图:
Map<Integer, Object> mapCompetencies = new TreeMap<Integer, Object>();
我想传给ListView
!!
我使用 LoadableDetachableModel
如下,但它会复制所有项目的数据。
IModel<List<Map.Entry<Integer, Object>>> mapModel = new LoadableDetachableModel<List<Entry<Integer, Object>>>() {
@Override
protected List<Entry<Integer, Object>> load() {
return new ArrayList<Map.Entry<Integer,Object>>(mapCompetencies.entrySet());
}
};
你为什么不为 listView 做这样的事情?
LoadableDetachableModel<Map<Integer,Object>> model = new LoadableDetachableModel<Map<Integer,Object>>() {
@Override
protected Map<Integer, Object> load() {
// TODO Auto-generated method stub
return mapCompetencies;
}
};
ListView lv = new ListView("id",new ArrayList<Integer>(model.getObject().keySet())){
@Override
protected void populateItem(ListItem<Integer> item) {
//do something here
//to take the object , you could just do
Object o = model.getObject().get(item);
}
}
我有以下地图:
Map<Integer, Object> mapCompetencies = new TreeMap<Integer, Object>();
我想传给ListView
!!
我使用 LoadableDetachableModel
如下,但它会复制所有项目的数据。
IModel<List<Map.Entry<Integer, Object>>> mapModel = new LoadableDetachableModel<List<Entry<Integer, Object>>>() {
@Override
protected List<Entry<Integer, Object>> load() {
return new ArrayList<Map.Entry<Integer,Object>>(mapCompetencies.entrySet());
}
};
你为什么不为 listView 做这样的事情?
LoadableDetachableModel<Map<Integer,Object>> model = new LoadableDetachableModel<Map<Integer,Object>>() {
@Override
protected Map<Integer, Object> load() {
// TODO Auto-generated method stub
return mapCompetencies;
}
};
ListView lv = new ListView("id",new ArrayList<Integer>(model.getObject().keySet())){
@Override
protected void populateItem(ListItem<Integer> item) {
//do something here
//to take the object , you could just do
Object o = model.getObject().get(item);
}
}