剑道 UI 树视图上下文右键单击会混淆选择

Kendo UI TreeView context-right click confuses selection

本文关键字:选择 单击 右键 UI 视图 上下文 剑道      更新时间:2023-09-26

下面我试图简化更复杂的 TreeView 用法,其中我未能在 TreeView 节点项上实现上下文菜单,变成一个表现出潜在相关问题的小提琴。步骤:在我的简化示例中,单击左键选择一个节点,然后在另一个节点上单击鼠标右键,最后通过转义关闭,然后选择指示被混淆。我尝试了"返回错误",选择(什么都没有),并阻止默认()无济于事。

我的问题是:这是剑道UI中的错误,还是我在使用TreeView时遗漏了一些东西?

https://jsfiddle.net/3cp9m8wo/

<div id='Tree_Space'></div>
<script type='text/x-kendo-template' id='Tree_template'>
    #= item.Name#
</script>
<script>
    $('#Tree_Space').kendoTreeView({
        dataSource: [ { Name: 'Top', items: [ { Name:'Item' }, { Name:'Item' } ] } ],
        template: kendo.template($('#Tree_template').html())
    });
    $("#Tree_Space").data("kendoTreeView").expand('.k-item');
</script>

我的全部目标是完全禁用 TreeView 节点上的剑道 UI 选择,允许我为放置在树节点中的元素实现左键单击(操作)和右键单击(上下文菜单)。但是,我还没有看到在树视图上禁用选择的方法。我确实发现 JQuery.click() 似乎确实有效并取消选择 Kendo UI 选择,但 Kendo UI 上下文菜单在右键单击时无法弹出,并显示其他工件 - 其中一个我想我已经在这里隔离了希望学到一些东西。

您可以尝试在模板中使用某些内容来控制这一点:

   <script type='text/x-kendo-template' id='Tree_template'>
        //Ideally, your server will return a collection that determines if the item can be selected, likewise, you could add a IsParentNode or something to indicate the item should be treated differently. 
        #if (item.CanSelect != 'null' && item.CanSelect==true)  { #
            <span>#: item.Name#</span>    
        #}else{#
            <span class='no-select'>#: item.Name#</span>    
        #}#   
   </script>
   <script type="text/javascript">
       $(document).ready(function () {
           //Add code here to tie into the onmousedown of all .no-select elements
            $(document).on("click", "no-select", function (e) {
                    e.preventDefault();                   
            });
       });
  </script>