问题描述
我在 Vaadin 14 中使用了一个 ListBox,它由带有自定义对象列表的 setItems 填充。有两件事我不知道该怎么做:
- 当项目列表改变时重新加载列表框
- 从列表框中删除某个对象
解决方法
您可以从基础集合中添加/删除项目,然后调用 ListBox.getDataProvider().refreshAll()
。
例如
ListBox<String> listBox = new ListBox<>();
List<String> items = new ArrayList<>();
items.add("one");
items.add("two");
listBox.setItems(items);
Button addItem = new Button("add item",e -> {
items.add("three");
listBox.getDataProvider().refreshAll();
});
add(listBox,addItem);