【问题标题】:Showing menu when right clicking on a item of a tree view右键单击树视图的项目时显示菜单
【发布时间】:2017-08-21 09:40:56
【问题描述】:

我有一个树视图,我想为不同的项目添加右键单击支持。我就是这样做的:

http://jsfiddle.net/doonot/xWjSz/

该菜单仅显示第一个根模块(右键单击后),而不显示其余根模块。你能告诉我为了获得所有根模块的菜单我必须改变什么吗?

非常感谢,非常感谢您的回答。

【问题讨论】:

  • 你好,我可以给你一个非常简单的 jsfiddle 对你有用它会捕获你的右键单击吗?请让我知道这是否适合你 bruv 将使用树形视图更新答案,祝你好运:) Cheerios!
  • 是的,那就太好了。给我一分钟,我将在上面添加我的树视图的一部分!顺便说一句,我正在使用 jquery-treeview。
  • 给我 2 分钟!欢呼雀跃!

标签: java javascript jquery html treeview


【解决方案1】:

Hiya 请看这个演示 http://jsfiddle.net/hYJPv/1/ http://jsfiddle.net/hYJPv/(已修复问题) diff 方法在这里http://jsfiddle.net/UeqBk/for_Dooonot_from_Tats_innit/

rightclick 上,您会收到警报。

代码

$(document).ready(function()
{
    // If you want to disable showing the context menu when right clicking
    // on the document, the code below would do the trick.
    $(document).bind("contextmenu",function(e)
    {
        alert('right click capture');
        return false;
    }); 

    var $tree = $("#tree").kendoTreeView(
    {
        select: function (event)
        {
            var $item = $(event.node);
            console.log( $item );
            alert( "selected" );
        }
    });


    // Find the item you want to select...
    var $selected = $('#selected');
    var $treePath = $selected.parentsUntil($tree, "li");

    var treeView = $tree.data('kendoTreeView');

    // Expand the tree in order to show the selected item
    treeView.expand( $treePath );

    // Gotta make both calls...
    treeView.select( $selected );
    treeView.trigger( 'select', {node: $selected} );
});
​

【讨论】:

  • 谢谢!但我不确定这是否真的是我需要的。我能够捕获右键单击,甚至显示菜单,但仅适用于树视图中的第一项。它不适用于其余项目。我不知道,该怎么做。你知道吗?
  • @dooonot no probs bruv,您的意思是在我给出的示例中还是在您的示例中?对不起,如果这听起来有点密集:Pjust确保我理解你的意思!干杯!
  • 在我提供的示例中。我实际上正在使用这个tutorial
  • @dooonot saweet!啊哈 okies 等会试一试,给我 10 个。
  • 哟 @dooonot 这就是你需要的:jsfiddle.net/Mhq2j/2 让我知道 bruv B-) !欢呼
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-21
  • 1970-01-01
  • 2012-07-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多