0

我正在使用 vaadin 14.2.2 进行测试。但是,我立即使用 Grid 解决了第一个问题。来自https://vaadin.com/docs/v14/flow/components/tutorial-flow-grid.html的示例

List<Person> people = Arrays.asList(
        new Person("Nicolaus Copernicus", 1543),
        new Person("Galileo Galilei", 1564),
        new Person("Johannes Kepler", 1571));

// Create a grid bound to the list
Grid<Person> grid = new Grid<>();
grid.setItems(people);
grid.addColumn(Person::getName).setHeader("Name");
grid.addColumn(Person::getYearOfBirth)
        .setHeader("Year of birth");

layout.add(grid);

不会在可视化中生成输出。还有几个 GitHub 问题中的提示使用

grid.setSizeFull();

不能解决这个问题。有谁知道如何解决这个问题?

4

1 回答 1

0

以下代码片段适用于 Vaadin 14.2.2 + Spring:

@Route("MainView")
public class MainView extends VerticalLayout {

    public MainView() {
        List<Person> people = Arrays.asList(
                new Person("Nicolaus Copernicus", 1543),
                new Person("Galileo Galilei", 1564),
                new Person("Johannes Kepler", 1571));

        // Create a grid bound to the list
        Grid<Person> grid = new Grid<>();
        grid.setItems(people);
        grid.addColumn(Person::getName).setHeader("Name");
        grid.addColumn(Person::getYearOfBirth).setHeader("Year of birth");

        add(grid);
    }

    class Person {
        String name;
        Integer yearofbirth;

        public Person(String name, Integer yearofbirth) {
            this.name = name;
            this.yearofbirth = yearofbirth;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getYearOfBirth() {
            return yearofbirth;
        }

        public void setYearOfBirth(Integer yearofbirth) {
            this.yearofbirth = yearofbirth;
        }
    }
}
于 2020-06-29T11:40:23.920 回答