从 Vaadin ListBox 重新加载和删除

问题描述

我在 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);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...