我正在尝试在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);
}
我扩展了所有节点,但它似乎没有被选中。
答案 0 :(得分:0)
您是否希望扩展和选择所有节点,包括任何深度的所有子节点?
然后你需要递归地调用expandChildren
并将子项添加到[(selection)]
,因为它只适用于引用。