简体   繁体   English

如何以编程方式选择treeList中的节点(Kendo)

[英]How to programatically select a node in a treeList (Kendo)

Is there a way to select a node in a treeList by default ? 有没有一种方法可以默认选择treeList中的节点?

How can I select a node in a treeList programmatically ? 如何以编程方式在treeList中选择一个节点?

Is there a method similar to findByUid as in a treeView ? 有没有类似于treeView中的findByUid的方法?

Sure, there is a method called select() : 当然,有一个叫做select()的方法:

var tr = $("#treelist .k-grid-content tr:first"); // The row
$("#treelist").data("kendoTreeList").select(tr);

The method accepts only a tr element. 该方法仅接受tr元素。

Demo . 演示

If you want to select a Node by default, you can do it by setting the node's selected property to true when you initialise the dataSource. 如果要默认选择一个节点,可以通过在初始化数据源时将节点的selected属性设置为true来进行selected Another option would be to call the TreeView select() method after the TreeView completed the data loading. 另一个选择是在TreeView完成数据加载之后调用TreeView select()方法。 (See the dataBound event for more details since the TreeView initialization may be completed before the data gets fully loaded) (有关更多详细信息,请参见dataBound事件,因为TreeView初始化可能在数据完全加载之前完成)

For the selection, there's a findByUid method that can be used in the TreeView. 对于选择,有一个可在TreeView中使用的findByUid方法。 The findByUid function will return the jQuery nodes matching the specified uid . findByUid函数将返回与指定uid匹配的jQuery节点。 You can then use the results to select a node programatically by using the select() method: 然后,可以通过使用select()方法使用结果以编程方式选择一个节点:

var dataItem = treeview.dataSource.get(10);
var node = treeview.findByUid(dataItem.uid);
treeview.select(node);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM