我试图迭代我的节点以编程方式设置要选择的节点。选定的节点存储在selectedFile3
中,但它没有长度,因此我无法迭代它以查找所有选定的节点。
如果我打印selectedFile3
到控制台它有长度......任何人都有如何实现这一点的线索?
<p-tree [value]="filesTree11" layout="horizontal" selectionMode="checkbox" [(selection)]="selectedFile3" [propagateSelectionUp]="true" [propagateSelectionDown]="false" (onNodeSelect)="test()"></p-tree>
app.component.ts
export class AppComponent implements OnInit {
title = 'app';
filesTree11: TreeNode[];
selectedItems: TreeNode;
msgs: Message[];
arr: TreeNode[] = new Array();
constructor(private nodeService: NodeService) { }
ngOnInit()
{
this.nodeService.getFiles().then(files => {
this.filesTree11 = [{
label: 'Root',
children: files
}];
});
}
test(node)
{
console.log(this.selectedItems);
console.log("length : " + this.selectedItems.length);
}
更新 https://github.com/primefaces/primeng/blob/master/src/app/showcase/components/tree/treedemo.ts
的示例中存在错误selectedFile3: TreeNode; // should be TreeNode[]
答案 0 :(得分:0)