我根据所选数据的父节点和子节点的数量创建了一个树,但在渲染树之后,我不知道我必须通过默认选择的所选数据的节点。那么我怎样才能搜索所需的节点并将其选中?
<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>
和我们的视图模型
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");
}
答案 0 :(得分:1)
更改selectedItem="@bind(vm.selectedPeopleTreeNode)"
使用bind代替加载
您可以对父组件使用Invalidate,因为通知会出现一些时间问题。