右键单击树视图的项目时显示菜单

时间:2012-05-02 11:43:02

标签: java javascript jquery html5 treeview

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

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

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

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

1 个答案:

答案 0 :(得分:2)

Hiya 请参阅此演示 http://jsfiddle.net/hYJPv/1/ http://jsfiddle.net/hYJPv/(修复此问题)差异接近此处{ {3}}

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} );
});
​