Kendo UI TreeView动态启用/禁用拖放事件

Kendo UI TreeView enable/disable dragAndDrop event dynamically

本文关键字:拖放 事件 启用 UI TreeView 动态 Kendo      更新时间:2023-09-26

我想知道如何通过javascript/jQuery动态启用dragAndDrop功能。

我知道这可以在初始化时用下面的代码片段完成:

$("#treeview").kendoTreeView({
  dragAndDrop: true,
  dataSource: [
    { text: "foo" },
    { text: "bar" }
  ]
});

但是我想要这个dragAndDrop功能与切换按钮,我的意思是启用/禁用dragAndDrop功能在树节点与按钮点击。

任何代码片段都对我很有帮助。

请尝试使用下面的代码片段。

<body>
    <div id="treeview"></div>
    <br />
    s
    Drag Drop Enabled:-
    <input type="checkbox" id="chkDragNDrop" />
    <script>
        $("#treeview").kendoTreeView({
            dragAndDrop: true,
            dragstart: onDragStart,
            dataSource: [
              { text: "foo" },
              { text: "bar" }
            ]
        });
        function onDragStart(e) {
            if ($("#chkDragNDrop").prop("checked") == false) {
                e.preventDefault();
            }
        }
    </script> 
</body>