从 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);