如何在DataSource完成后展开阅读完成加载Telerik MVC TreeView(Kendo UI)

问题描述:

如何在数据加载后让我的TreeView展开?如何在DataSource完成后展开阅读完成加载Telerik MVC TreeView(Kendo UI)

 @(Html.Kendo().TreeView() 
       .Name("OrganizationTree") 
       .HtmlAttributes(new { @class = "demo-section" }) 
       .DataTextField("Name") 
       .DragAndDrop(true) 
       .ExpandAll(true) 
       .Events(events => events 
         .Select("onOrgSelect") 
         .Drop("onOrgDrop") 
       ) 
       .DataSource(dataSource => dataSource 
        .Model(m=> m 
         .Id("ID") 
         .HasChildren("HasChildren") 
        ) 
        .Read(read => read 
         .Action("Organizations_Read", "Organizations") 
        ) 
       ) 
     ) 

我想通了。这与Petur的链接不同,因为它不是纯粹的“Kendo UI”,而是Telerik的使用Kendo UI框架的“ASPNET MVC UI”。

 @(Html.Kendo().TreeView() 
       .Name("OrganizationTree") 
       .HtmlAttributes(new { @class = "demo-section" }) 
       .DataTextField("Name") 
       .DragAndDrop(true) 
       .ExpandAll(true) 
       .Events(events => events 
         .Select("onOrgSelect") 
         .Drop("onOrgDrop") 
         .DataBound("onDataBound") //I ADDED THIS HERE 
       ) 
       .DataSource(dataSource => dataSource 
        .Model(m=> m 
         .Id("ID") 
         .HasChildren("HasChildren") 
        ) 
        .Read(read => read 
         .Action("Organizations_Read", "Organizations") 
        ) 
       ) 
     ) 

这我需要在头标记此功能:

<script> 
    function onDataBound(e) 
    { 
     $("#OrganizationTree").data("kendoTreeView").expand(".k-item") 
    } 
</script>