2015-03-08 108 views
0

如何在數據加載後讓我的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") 
        ) 
       ) 
     ) 

回答

0

我想通了。這與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>