从 Vaadin ListBox 重新加载和删除
Reloading and deleting from Vaadin ListBox
我在 Vaadin 14 中使用 ListBox,它由带有自定义对象列表的 setItems 填充。有两件事我不知道该怎么做:
- 项目列表更改后重新加载列表框
- 正在从列表框中删除某个对象
您可以 add/remove 基础集合中的项目,然后调用 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);
我在 Vaadin 14 中使用 ListBox,它由带有自定义对象列表的 setItems 填充。有两件事我不知道该怎么做:
- 项目列表更改后重新加载列表框
- 正在从列表框中删除某个对象
您可以 add/remove 基础集合中的项目,然后调用 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);