【问题标题】:Prime NG : tree propagateSelectionUp in typescriptPrimeng:树在打字稿中传播选择
【发布时间】: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


    【解决方案1】:

    我找到了解决方案:

    country.partialSelected = true;
    continent.partialSelected = true;
    

    只需要添加一些条件来检查是否所有的孩子都被选中。

    【讨论】:

      【解决方案2】:

      已解决 :) !!!!!!!!!

      你应该在这个属性中使用括号

      [propagateSelectionUp]="假" [propagateSelectionDown]="假"

      【讨论】:

        猜你喜欢
        • 2017-12-09
        • 1970-01-01
        • 1970-01-01
        • 2016-03-14
        • 2020-08-21
        • 2021-05-12
        • 1970-01-01
        相关资源
        最近更新 更多