尝试在此柱塞中的treeview节点上使用focus()进行ElementRef。我在底线上评论了这两行,因为它们不起作用。
下面是代码清单的柱塞:
https://plnkr.co/edit/aUnechu6glXk5CMFsMex?p=preview
import { Component, ElementRef, ViewChild } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<kendo-treeview
#treeview
[nodes]="data"
textField="text"
kendoTreeViewCheckable
kendoTreeViewExpandable
kendoTreeViewSelectable
kendoTreeViewHierarchyBinding
childrenField="items">
</kendo-treeview>
`
})
export export class AppComponent {
@ViewChild("treeview") treeview: ElementRef;
public data: any[] = [
{
text: "Furniture", items: [
{ text: "Tables & Chairs" },
{ text: "Sofas" },
{ text: "Occasional Furniture" }
]
},
{
text: "Decor", items: [
{ text: "Bed Linen" },
{ text: "Curtains & Blinds" },
{ text: "Carpets" }
]
}
];
//let tree = this.treeview.nativeElement;
//this.treeview.focus('0');
}
根据它们的文档和示例,focus()方法如下:
https://www.telerik.com/kendo-angular-ui/components/treeview/api/TreeViewComponent/#toc-focus
如何在组件代码中以编程方式聚焦(),而不是放在文档中的click()事件?
https://stackoverflow.com/questions/49779517
复制相似问题