-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi.
The api for Tree.getItems() says: "Returns a readonly list of all descending Treeitem (children's children and so on)."
But in contrast to the api, the list only contains the children of the root node. Did i misunderstood the api?
I'm using version 3.6.2.
i tried to workaround this problem with this code.
protected <T> void setSelectedValues(Tree tree, Collection<T> selectedValues, boolean add) { if (!add) tree.clearSelection(); for (Object o: tree.getItems()) { Treeitem item = (Treeitem) o; setSelectedValues(tree, item, selectedValues); } } @SuppressWarnings("unchecked") private <T> void setSelectedValues(Tree tree, Treeitem currentItem, Collection<T> selectedValues) { T value = (T) currentItem.getValue(); if (selectedValues.contains(value)) { tree.addItemToSelection(currentItem); } Treechildren children = currentItem.getTreechildren(); if (children != null) { for (Object o: children.getItems()) { Treeitem child = (Treeitem) o; setSelectedValues(tree, child, selectedValues); } }
The problem is that treeitem.getTreechildren().getItems().size() is allways zero! I know that the tree has multiple levels... i see it.
whats wrong here?
Hi,
The getItems() will return all of its child items whatever it is visible or not
For example, it works well.
<zk> <tree id="tree" width="400px" rows="8"> <treecols sizable="true"> <treecol label="Name" /> <treecol label="Description" /> </treecols> <treechildren> <treeitem> <treerow> <treecell label="Item 1" /> <treecell label="Item 1 description" /> </treerow> </treeitem> <treeitem open="false"> <treerow> <treecell label="Item 2" /> <treecell label="Item 2 description" /> </treerow> <treechildren id="tc"> <treeitem> <treerow> <treecell label="Item 2.1" /> </treerow> <treechildren> <treeitem> <treerow> <treecell label="Item 2.1.1" /> </treerow> </treeitem> <treeitem> <treerow> <treecell label="Item 2.1.2" /> </treerow> </treeitem> </treechildren> </treeitem> <treeitem> <treerow> <treecell label="Item 2.2" /> </treerow> <treechildren> <treeitem> <treerow> <treecell label="Item 2.2.1" /> </treerow> </treeitem> </treechildren> </treeitem> </treechildren> </treeitem> <treeitem label="Item 3" /> </treechildren> </tree> <button label="show items" onClick='alert(tc.getItems().size())'/> </zk>
/Jumper
thanks for your reply.
in contrast to your example i'm using a tree model:
<tree id="treeModules" multiple="true" checkmark="true" model="${myComposer.availableModules}"> <treefoot> <treefooter label="Quelle: ${myComposer.moduleService.applicationWrapper.name}"/> </treefoot> </tree>
the tree shows initially only the root expanded.
and you can trust me - Tree.getItems() will only return the root children in this case.
It is a link, you can click upon it. - http://www.zkoss.org/javadoc/3.6/zk/org/zkoss/zul/Tree.html#renderItem%28org.zkoss.zul.Treeitem%29
Asked: 2009-10-06 11:59:46 +0800
Seen: 1,395 times
Last updated: Jan 31 '11