-
Bug
-
Resolution: Fixed
-
Normal
-
6.5.2
-
None
http://screencast.com/t/UOk4OmvHwYnF
when we just want to reload the path list, the whole menubar will be renderer.
<zk> <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.zkoss.test.testZK65.MyViewModel2')"> <menubar id="mbar" children="@bind(vm.root.children) @template(empty each.children?'menuitem':'menu')"> <template name="menu" var="node"> <menu label="@bind(node.name)"> <menupopup children="@bind(node.children) @template(empty each.children?'menuitem':'menu')" /> </menu> </template> <template name="menuitem" var="node"> <menuitem label="@bind(node.name)" onClick="@command('menuClicked',node=node)" /> </template> </menubar> <hlayout children="@load(vm.path)"> <template name="children"> <label value="@load(each.name)"/> >> </template> </hlayout> <button label="update path" onClick="@command('updatePath')"/> </window> </zk>
package org.zkoss.test.testZK65; import java.util.ArrayList; import java.util.List; import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; import org.zkoss.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.test.testZK65.MyViewModel2.Node; public class MyViewModel2 { private Node root; private Node selectedNode; private List<Node> path; @Init public void init() { root = new Node("Root"); Node nodeA = new Node("Item A"); Node nodeB = new Node("Item B"); Node nodeC = new Node("Item C"); root.appendChild(nodeA); root.appendChild(nodeB); root.appendChild(nodeC); Node nodeA1 = new Node("Item A1"); Node nodeA2 = new Node("Item A2"); nodeA.appendChild(nodeA1); nodeA.appendChild(nodeA2); Node nodeB1 = new Node("Item B1"); Node nodeB2 = new Node("Item B2"); nodeB.appendChild(nodeB1); nodeB.appendChild(nodeB2); } public Node getRoot() { System.out.println("-------------------load root--------------"); return root; } public Node getSelectedNode() { return selectedNode; } public List<Node> getPath() { return path; } @Command @NotifyChange("path") public void menuClicked(@BindingParam("node")Node selectedNode ) { this.selectedNode = selectedNode; if (path == null) path = new ArrayList<Node>(); else path.clear(); Node curNode = selectedNode; while (curNode != null) { path.add(0, curNode); curNode = curNode.getParent(); } } @Command @NotifyChange("path") public void updatePath() { path.add(new Node("new")); } public static class Node { private String name; private List<Node> children; private Node parent; public Node(String name) { super(); this.name = name; } public String getName() { return name; } public List<Node> getChildren() { return children; } public Node getParent() { return parent; } public void appendChild(Node child) { if (children == null) children = new ArrayList<Node>(); children.add(child); child.parent = this; } public void removeChild(Node child) { if (children == null) return; children.remove(child); child.parent = null; } } }