【发布时间】:2018-07-10 09:02:44
【问题描述】:
我是一名使用 JHipster 构建并使用 Angular 4.3 和 PrimeNG 的应用程序的初学者。 我有一棵树和一个搜索栏。
但是我有一个问题,当我在搜索栏中进行研究时,我使用打字稿代码手动打开树,当我将右叶放入所选节点时,它不会检查国家和大陆(父节点):
这是我的 HTML 代码:
<jhi-search-bar [data]="items" (onItemSelected)="openNodeAfterSearch($event)"></jhi-search-bar>
<p-tree class="arbre"
[loading]="loading"
[value]="nodes"
selectionMode="checkbox"
(onNodeSelect)="onChange()"
(onNodeUnselect)="onChange()"
[(selection)]="selectedNodes"></p-tree>
这是我的 TS 代码:
openNodeAfterSearch(item: any) {
const racine = this.nodes[0];
// I close all unecessary opened nodes
for (const continent of racine.children) {
continent.expanded = false;
for (const country of continent.children) {
country.expanded = false;
for (const item of country.children) {
if (item.data.id === item.item.id) { // right node to open
this.selectedNodes = [];
this.selectedNodes.push(item);
country.expanded = true; // open parent's node
continent.expanded = true;
}
}
}
}
}
我已经尝试过这个 HTML 属性,但失败了:
[propagateSelectionUp]="true"
我也不想这样继续下去:
this.selectedNodes.push(country);
this.selectedNodes.push(continent);
因为我得到了这个:
有人有想法吗?
朱莉。
【问题讨论】:
标签: angular typescript tree primeng