Configuring jstree right-click contextmenu for different node types

前端 未结 8 2314
甜味超标
甜味超标 2020-12-04 07:29

I\'ve seen an example somewhere online showing how to customise the appearance of jstree\'s right-click context menu (using contextmenu plugin).

For example, allow

8条回答
  •  一生所求
    2020-12-04 07:54

    Implemented with different node types:

    $('#jstree').jstree({
        'contextmenu' : {
            'items' : customMenu
        },
        'plugins' : ['contextmenu', 'types'],
        'types' : {
            '#' : { /* options */ },
            'level_1' : { /* options */ },
            'level_2' : { /* options */ }
            // etc...
        }
    });
    

    And the customMenu function:

    function customMenu(node)
    {
        var items = {
            'item1' : {
                'label' : 'item1',
                'action' : function () { /* action */ }
            },
            'item2' : {
                'label' : 'item2',
                'action' : function () { /* action */ }
            }
        }
    
        if (node.type === 'level_1') {
            delete items.item2;
        } else if (node.type === 'level_2') {
            delete items.item1;
        }
    
        return items;
    }
    

    Works beautifully.

提交回复
热议问题