gpt4 book ai didi

java - 如何在ZK中的TreeNode结构中选择树节点?

转载 作者:行者123 更新时间:2023-12-01 13:18:34 25 4
gpt4 key购买 nike

我已经根据 selectedData 的父节点和子节点的数量创建了一棵树,但是在渲染树之后,我不知道必须默认选择的 selecteddata 的节点。那么如何搜索所需的节点并使其被选中呢?

<tree model="@load(vm.peopleTreeModel)"
selectedItem="@load(vm.selectedPeopleTreeNode)"
sizedByContent="true" droppable="true" width="100%" vflex="1"
hflex="1" visible="@load(vm.relatedView)">
<template name="model" var="node">
<treeitem open="@bind(node.open)">
<treerow>
<treecell
label="@bind(node.data.name)" sclass="field-label"
onClick="@command('showPeopleDetailFromTree' , peopleRSN=node.data.description)"
onDoubleClick="@command('showPeopleDetailOnDoubleClickFromTree' , peopleRSN=node.data.description)" />
</treerow>
</treeitem>
</template>
</tree>

和我们的 View 模型

public void createPeopleTreeModel(int argpeopleID) {
parentNodeChildList = new ArrayList<Integer>();
treeNodeMap = new HashMap<Integer, DemoTreeNode>();
Integer peopleID;
List<Integer> peopleIDList = new ArrayList<Integer>();
for (Integer peopleId : childrenList) {
peopleIDList.add(peopleId);
String peopleName = Services.peopleService().getPeopleNameByPeopleID(peopleId);

treeNodeMap.put(peopleId, new DemoTreeNode(new FolderTree(peopleName, peopleId.toString()), new DemoTreeNode[] {}, true));

}
for (Integer peopleIDTemp : peopleIDList) {
Result<Record> recordList = Transaction.current().select(People.PEOPLE.PEOPLE_ID).from(People.PEOPLE)
.where(People.PEOPLE.PARENT_ID.eq(peopleIDTemp)).fetch();

DemoTreeNode treeNode = (DemoTreeNode) treeNodeMap.get(peopleIDTemp);
if (recordList.size() > 0) {
for (Record record : recordList) {
peopleID = record.getValue(People.PEOPLE.PEOPLE_ID);
DemoTreeNode treeChildNode = treeNodeMap.get(peopleID);
treeChildNode.setOpen(true);
treeNodeMap.put(peopleID, treeChildNode);
treeNode.add(treeChildNode);
if (peopleIDTemp == argpeopleID) {
parentNodeChildList.add(peopleID);
}
}
}
treeNodeMap.put(peopleIDTemp, treeNode);// Here I am putting the treenode and below checking the selected data condition I set the selected peopleTree Node to it selected, but it is not working.
if (selectedPeopleData.getPeopleID() == peopleIDTemp) {
setSelectedPeopleTreeNode(treeNode);
}
}
List<DemoTreeNode> rootNodeChildList = new ArrayList<DemoTreeNode>();
rootNodeChildList.add(treeNodeMap.get(argpeopleID));
DemoTreeNode[] rootNodeArray = new DemoTreeNode[rootNodeChildList.size()];
rootNodeChildList.toArray(rootNodeArray);
DemoTreeNoderootNode = new DemoTreeNode(null, rootNodeArray, true);
peopleTreeModel = new DemoTreeModel(rootNode);

BindUtils.postNotifyChange(null, null, this, "peopleTreeModel");
BindUtils.postNotifyChange(null, null, this, "selectedPeopleTreeNode");
}

最佳答案

更改selectedItem="@bind(vm.selectedPeopleTreeNode)"

使用bind代替load

并且您可以对父组件使用 Invalidate,因为通知时会出现一些时间问题。

关于java - 如何在ZK中的TreeNode结构中选择树节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22246790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com