-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I want to create a dynamic tree so that when I press a button from node/leaf item(let say my node/and leaf has a label: "NodeName", and a button: "Add Child") it adds a new child to the selected node/leaf. Now I can add children to a node but can't add children to a leaf. I need also to add children to a leaf.
I have an idea to convert a leaf into node and after that to add children to the leaf-node. Any idea how implement this or any other solution, please?
Thanks.
Hello ZKL,
A solution to your issue could be the following:
Store into a collection all the categories, and leaf nodes (I would create a model that would store an id, parentId, name, and position)
Insert into the collection the new object (when the user presses the add button. Here you will have to pay attention to add it to the correct position in the collection)
Re-render the tree using the updated collection (If the object has children, then treat it as a category node, and if the object does not have children then treat it as a leaf node)
Hope this pattern will help.
Best Regards,
Darksu
Hello Darksu,
If I understand you correctly, Your suggestion is to refresh the tree after each node insertion, this means that we should to save the current state of tree('open' property of each node), because: after refresh, the tree is shown by default with all nodes closed.
I found the 'insertBefore' method of Treeitem, it seems that can convert a leaf treeitem into a category treeitem, but without children nodes. Does someone used this method in a tree? Can be achieved my objective using 'insertBefore' method?
Asked: 2014-08-07 08:47:03 +0800
Seen: 40 times
Last updated: Aug 11 '14
ZK7 TreeDataEvent.SELECTION_CHANGED possible bug
SimpleTreeNode in ZK version 7.0.2
Problem with DefaultTreeModel (Treeitem)
Large Tree with dynamic columns
Tree width lost after changing col width on maximized panel
MVVM tree example to show add/insert/delete/move/drag?
Error writing 'checked' on type org.zkoss.zul.Checkbox [closed]
Hello, have you tried to use DefaultTreeModel and configure it to treat the zero size of children node as a leaf node? Please refer reference.
RaymondChao ( 2014-08-08 02:43:21 +0800 )editIf I add a new leaf with zero size of children, this leaf is shown as a category node(with arrow), but I want to have a leaf node(without arrow) and only after I adding a child to it, to convert the leaf node into a category node.
ZKL ( 2014-08-08 08:19:03 +0800 )edit