【问题标题】:PrimeNG Tree expandedPrimeNG 树扩展
【发布时间】:2018-05-15 20:00:35
【问题描述】:

我正在尝试在 PrimeNG 树中设置选定的项目。

HTML

<p-tree  id="selectedProducts" *ngIf="selectedCustomer != null"
[value]="tree" selectionMode="checkbox"
[(selection)]="selectedProducts"
(click)="fileterProducts()"></p-tree>

TS

selectedProducts: TreeNode[] = [];
filteredProducts: number[] = [];
tree: TreeNode[] = [];

selectCustomer(customerId: number){
this.selectedCustomer = this.selectedCustomers.find(r => r.Name == this.userForm.value.Customers[0]);
console.log("Customer Products ");
console.log(this.selectedCustomer.selectedProducts);


this.selectedProducts = this.selectedCustomer.selectedProducts;

for ( let product of this.selectedProducts ) {
  product.expanded = true;
  this.expandChildren(product);
  console.log('Product : ');
  console.log(product);
}

我把所有节点都展开了,但它似乎没有被选中。

【问题讨论】:

  • 你能分享你的组件TS代码吗?
  • 我在上面添加了代码
  • 但它似乎没有被选中 你的意思是复选框没有被选中或者叶子没有被展开?你能创建一个 StackBlitz 吗?

标签: angular primeng primeng-treetable


【解决方案1】:

是否要展开和选择所有节点,包括任意深度的所有子节点?

然后您需要递归调用expandChildren 并将子代添加到[(selection)],因为它仅适用于引用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-02
    • 2017-07-21
    • 1970-01-01
    • 2017-11-15
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多