使用Kendo UI selectedKeys
属性,保留用户选择的treeview
项目。我也有一个使用@ViewChild()
定义的treeview元素。我的问题是如何以编程方式选择项目。
这是我的参考资料: https://www.telerik.com/kendo-angular-ui/components/treeview/selection/
这是我更新treeviewData
数组的地方:
// BIND TO KENDO TREEVIEW
that.treeviewData = new Array();
that.treeviewData.push(tree);
this.selectedKeys
显示:
["0_0_0_2_0"]
和我的treeview
模板代码:
<kendo-treeview #treeview id='treeview'
[nodes]="treeviewData"
[textField]="['SiteName', 'LocationName', 'HostName', 'Url']"
kendoTreeViewExpandable
[(expandedKeys)]="expandedKeys"
(expand)="treeExpand($event)"
kendoTreeViewSelectable="{ mode: 'single' }"
[selectBy]='SiteName || LocationName || HostName || Url'
[(selectedKeys)]="selectedKeys"
(selectionChange)="treeSelection($event)"
kendoTreeViewHierarchyBinding
childrenField="subs" >
<ng-template kendoTreeViewNodeTemplate let-dataItem>
<span style="padding-left: 5px;">
{{dataItem.LocationName || dataItem.HostName || dataItem.SiteName )}}
</span>
</ng-template>
</kendo-treeview>