在Primefaces中,我想展开<p:treeNode>
,当我点击它的标签时,而不是当我点击小三角形时。
无法找到任何.xhtml文档,但发现节点是以这种方式创建的:
...
final TreeNode parentNode = this.addNode(false, "Parent", this.root, targetView1); //first parameter means start expanded or not
this.addNode(, "ChildNode", parentNode, "targetView2");
...
有可能吗?谢谢。
答案 0 :(得分:0)
以防任何人对我认为@Kukeltje所指的解决方案感兴趣的是我的解释:
XHTML:
<p:tree value="#{Bean.rootNode}" var="node" style="width: 100%" id="tree" selectionMode="single">
<p:treeNode id="node">
<h:outputText value="#{node.name}" />
</p:treeNode>
<p:ajax event="select" update=":form:tree" listener="#{Bean.onNodeSelect}" />
</p:tree>
豆:
public void onNodeSelect(NodeSelectEvent event) {
if (event.getTreeNode().isExpanded()) {
//closes if it is open.
event.getTreeNode().setExpanded(false);
} else {
//open if it is closed.
collapsingORexpanding(event.getTreeNode(), false);//this is so all children are closed under this node. trust me, you want this...
event.getTreeNode().setExpanded(true);
}
}
public void collapsingORexpanding(TreeNode n, boolean option) {
if (n.getChildren().isEmpty()) {
n.setSelected(false);
} else {
for (TreeNode s : n.getChildren()) {
collapsingORexpanding(s, option);
}
n.setExpanded(option);
n.setSelected(false);
}
}
答案 1 :(得分:0)
将selection添加到您的观看者:
[(selection)]="selectedTreeNode"
(onNodeSelect)="onNodeSelect($event)"
在控制器中定义您的值:
selectedTreeNode: TreeNode;
处理onNodeSelect()
:
onNodeSelect(event: any) {
this.selectedTreeNode.expanded = !this.selectedTreeNode.expanded;
}
干杯!