gpt4 book ai didi

kendo-ui-angular2 - Angular-Kendo treeview focus() 方法

转载 作者:行者123 更新时间:2023-12-03 22:51:33 27 4
gpt4 key购买 nike

正在尝试 focus()使用 ElementRef 在此 plunker 中的 Treeview 节点上。我评论了底部的两行,因为它们不起作用。

这是下面代码 list 的 plunker:

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() 相比,如何在我的组件代码中以编程方式进行 focus()在他们的文档中发布的事件?

最佳答案

代码需要在 Angular's lifecycle 之一内执行钩子(Hook)或来自方法。我们需要一个 ngAfterViewInit 或一个自定义的 AppComponent.focus() 方法,ViewChild有时间实例化 TreeView 实例:

ngAfterViewInit(){
//XXX: this.treeview is the TreeViewComponent instance set by ViewChild decorator
this.treeview.focus('1');
}

关于kendo-ui-angular2 - Angular-Kendo treeview focus() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49779517/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com