【发布时间】:2019-01-28 14:46:39
【问题描述】:
我有一个带有类别的 p-tree。 当我导航到具有类别 ID 的类别页面时,我希望 p-tree 专注于所需的类别。
HTML
<p-tree *ngIf="categoriesTree" [value]="categoriesTree" selectionMode="single" [selection]="getselectedCategory()" (onNodeSelect)="categorySelected($event)" ></p-tree>
我试图在 [selection] attr 处设置一个函数并返回一个节点,但它不起作用。
函数
public getselectedCategory(){
this.sortService.CategoryObjectOut.subscribe(val=>{
for(let i =0; i< this.categoriesTree.length;i++){
if(this.categoriesTree[i] == val.node){
this.selectedCategory=val
return this.selectedCategory.node;
}
}
})
}
例如,如果我设置 [selected]="categoriesTree[0]" 它工作正常。但我想动态地做。
有什么问题?
【问题讨论】:
-
我通过将全局参数添加到 [selected]="categoriesTree[X]" 解决了我的问题,当我到达此页面时,我发送所需类别的索引号 (X)。
标签: angular focus primeng treenode