无法扩展Kendo TreeView中的所有节点

时间:2014-02-06 10:18:15

标签: kendo-ui expand kendo-treeview

我想展示我的Kendo UI TreeView一直在扩展,但它只会显示崩溃。重新加载数据源时,我可以看到展开的树的闪光,然后它会折叠。

var locationTreeView = $("#treeViewLocations").kendoTreeView({
checkboxes: {
    checkChildren: false,
    template: "# if(item.showCheckbox){# <input type='checkbox' name='selectedLocations' value='#= item.value #' />#}#"
},
dataTextField: "text",
dataSource: {
    transport: {
        read: {
            url: window.location.origin + "/api/v1/bookingrequestlocation",
            dataType: "json",
            type: "GET",
            data: { bookingSeasonPeriodId: bookingSeasonPeriod.value() },
        }
    },
    schema: {
        model: {
            id: "value",
            children: "items",
            hasChildren: "hasChildren",
        }
    }
}}).data("kendoTreeView");

expandTreeView();

function changeSeason() {
    locationTreeView.dataSource.read();
    expandTreeView();}

function expandTreeView() {
    locationTreeView.expand(".k-item");}

3 个答案:

答案 0 :(得分:2)

在数据绑定事件中触发expandTreeView()函数

答案 1 :(得分:0)

它正在为我工​​作......谢谢......我添加了一个像这样的DataBound事件

.Events(e => e.DataBound("ExpandAllTree"))

并在那个方法中

function ExpandAllTree() {
        var treeview = $("#TreeView").data("kendoTreeView");
        treeview.collapse(".k-item");
    }

并且它完美运作......

答案 2 :(得分:0)

Add the following code right after creating the treeview 

 var tree = $("#TREEVIEWID").data("kendoTreeView");
        function expandTreeNodes() {
            if ($('.k-item').length) {
                var expandedLength = $('.k-item').length;
                tree.expand(".k-item");
                if (expandedLength < $('.k-item').length) {
                    expandTreeNodes();
                }
            }
        }