collapse - 由于在 kendo Treeview 中添加子项而更新其数据源时防止扩展父节点

标签 collapse expand kendo-treeview databound

我有一个带有 3 个根父节点的 kendotreeview。示例如下所示。
当我放下 child 3 进入 新建子群 ,节点“新子组”默认展开 即使它在之前被折叠.我想防止这种可能性。如果 新建子群 之前扩展过,那么我想保持原样。问题是 展开 之前被调用数据绑定(bind) 事件,因此我被困在这里。

请帮忙。

parent 1:

--New SubGroup  
--Child2  
--Child3 
--Child4   

parent 2:
--Child4  
--Child5  

Code snippet:
 dataBound: function (e) {
            console.log("DataBound", e.node);
            var nodedataitem = $("#DimMeasTree").data("kendoTreeView").dataItem($(e.node));
            if (nodedataitem.FieldKey === "SubGroup" && ($(e.node).attr("aria-expanded")) === "true") {
                
                $("#DimMeasTree").data("kendoTreeView").collapse($(e.node));
           }
        }

最佳答案

初始化 Treeview 后,我订阅了我自己的自定义扩展函数(即 subgroup_expand())。如下所示:

<div id="treeview"></div>
<script>
function subgroup_expand(e) {
   if (typeof event === 'undefined') {
        //If browser is Firefox, the subgroup will expand and do not close automatically.
        // It is because Firefox does not support "event" attribute gloabally as in IE or in Google chrome.
    }
   else if (!!e.node && typeof(event) !== 'undefined' && event.type !== "click" && event.type !== "dblclick") {
        var nodedataitem = $("#treeview").data("kendoTreeView").dataItem($(e.node));
        if (nodedataitem.FieldKey === "SubGroup") {
            // e.preventDefault();
            setTimeout(function () {
                //Collapse the subgroup if it was not expanded by click or dblclick.
                $("#treeview").data("kendoTreeView").collapse($(e.node));
            }, 50);
        }
    }
}
$("#treeview").kendoTreeView({
  dataSource: modeldata
});
var treeview = $("#treeview").data("kendoTreeView");
treeview.bind("expand", subgroup_expand);
</script>

关于collapse - 由于在 kendo Treeview 中添加子项而更新其数据源时防止扩展父节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30941791/

相关文章:

asp.net-mvc - Kendo UI Treeview 绑定(bind)

angularjs - 悬停时的 Kendo Treeview

html - 导航栏的 Bootstrap 切换未扩展

javascript - 如何在文档准备好时使 Jquery 可折叠面板折叠而不是展开?

JQuery 单击时切换行

r - R 中的 Proc 扩展

jquery - 无法在 Kendo UI 的 Treeview 中进行选择

html - Bootstrap 导航栏折叠未在单击时关闭

android - 在 Android 布局中折叠边距

twitter-bootstrap - Twitter Bootstrap,如何让折叠插件关闭打开的项目并在点击时打开新的项目