Vaadin - 如何将复选框组件添加到树中?
Vaadin - How add checkbox component to a tree?
我正在使用 Vaadin 7.5.3 开发 Web 应用程序。我需要一棵具有 select 可用节点的树。我想 select 使用复选框的节点。试了很多方法和目击后,我找不到如何将 CheckBox 组件添加到树节点。
据我所知,直到当前最新版本又名 Vaadin 7.5.6,这是不可能的,正如 Jouni 在此 discussion on their forums. He has also opened an improvement ticket 中指出的那样,但到目前为止我没有看到任何变化。
尽管如此,您应该能够 伪造 它,方法是使用 TreeTable component. You can find here 一个完整的示例,下面是它的摘录:
final TreeTable ttable = new TreeTable("My TreeTable");
ttable.addContainerProperty("Name", CheckBox.class, "");
ttable.addContainerProperty("City", String.class, "");
ttable.setWidth("20em");
// Create the tree nodes
ttable.addItem(new Object[]{new CheckBox("Root"), "Helsinki"}, 0);
ttable.addItem(new Object[]{new CheckBox("Branch 1"), "Tampere"}, 1);
ttable.addItem(new Object[]{new CheckBox("Branch 2"), "Turku"}, 2);
ttable.addItem(new Object[]{new CheckBox("Leaf 1"), "Piikkiö"}, 3);
ttable.addItem(new Object[]{new CheckBox("Leaf 2"), "Parainen"}, 4);
ttable.addItem(new Object[]{new CheckBox("Leaf 3"), "Raisio"}, 5);
ttable.addItem(new Object[]{new CheckBox("Leaf 4"), "Naantali"}, 6);
// Set the hierarchy
ttable.setParent(1, 0);
ttable.setParent(2, 0);
ttable.setParent(3, 1);
ttable.setParent(4, 1);
ttable.setParent(5, 2);
ttable.setParent(6, 2);
// Expand the tree
ttable.setCollapsed(2, false);
for (Object itemId: ttable.getItemIds())
ttable.setCollapsed(itemId, false);
ttable.setPageLength(ttable.size());
这是输出
这是一个老问题,所以它的价值:Vaadin 演示页面有一个例子:
http://demo.vaadin.com/book-examples/book#component.tree.itemstylegenerato
我正在使用 Vaadin 7.5.3 开发 Web 应用程序。我需要一棵具有 select 可用节点的树。我想 select 使用复选框的节点。试了很多方法和目击后,我找不到如何将 CheckBox 组件添加到树节点。
据我所知,直到当前最新版本又名 Vaadin 7.5.6,这是不可能的,正如 Jouni 在此 discussion on their forums. He has also opened an improvement ticket 中指出的那样,但到目前为止我没有看到任何变化。
尽管如此,您应该能够 伪造 它,方法是使用 TreeTable component. You can find here 一个完整的示例,下面是它的摘录:
final TreeTable ttable = new TreeTable("My TreeTable");
ttable.addContainerProperty("Name", CheckBox.class, "");
ttable.addContainerProperty("City", String.class, "");
ttable.setWidth("20em");
// Create the tree nodes
ttable.addItem(new Object[]{new CheckBox("Root"), "Helsinki"}, 0);
ttable.addItem(new Object[]{new CheckBox("Branch 1"), "Tampere"}, 1);
ttable.addItem(new Object[]{new CheckBox("Branch 2"), "Turku"}, 2);
ttable.addItem(new Object[]{new CheckBox("Leaf 1"), "Piikkiö"}, 3);
ttable.addItem(new Object[]{new CheckBox("Leaf 2"), "Parainen"}, 4);
ttable.addItem(new Object[]{new CheckBox("Leaf 3"), "Raisio"}, 5);
ttable.addItem(new Object[]{new CheckBox("Leaf 4"), "Naantali"}, 6);
// Set the hierarchy
ttable.setParent(1, 0);
ttable.setParent(2, 0);
ttable.setParent(3, 1);
ttable.setParent(4, 1);
ttable.setParent(5, 2);
ttable.setParent(6, 2);
// Expand the tree
ttable.setCollapsed(2, false);
for (Object itemId: ttable.getItemIds())
ttable.setCollapsed(itemId, false);
ttable.setPageLength(ttable.size());
这是输出
这是一个老问题,所以它的价值:Vaadin 演示页面有一个例子:
http://demo.vaadin.com/book-examples/book#component.tree.itemstylegenerato