0

我正在尝试在 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);
}

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

4

1 回答 1

0

您是否想要扩展和选择所有节点,包括任何深度的所有子节点?

然后你需要expandChildren递归调用并添加孩子[(selection)],因为它只适用于引用。

于 2018-05-15T12:00:35.787 回答