2012-03-09 69 views
3

我使用“文本菜单”和“类型”中jstree插件,并希望根据“类型”来定义不同的文本菜单,就像这样:如何在jstree中为不同的节点类型配置contextmenu?

$("#tree").jstree({ 
    "plugins" : [ "themes", "json_data", "ui", "contextmenu", "types" ], 
    "themes" : { 
     "url" : "css/jstree/themes/classic/style.css", 
     "theme" : "classic", 
     "icons" : false 
    }, 
    "json_data" : { "data" : data }, 
    "types": { 
     "types": { 
      "leaf": { "contextmenu" : { items : contextMenu } } 
     } 
    } 
}); 

,但它不工作时,会显示同样的文本菜单所有节点,没有为我定义的'叶'节点指定一个节点。是不是因为无法在类型中定义contextmenu?那么如何轻松实现这一点。

回答

7

您必须在上下文菜单插件部分定义上下文菜单。 我认为目前最好的方法是定义所有节点的所有项目,然后根据节点类型删除项目,甚至更好 - 定义一个函数,根据节点返回上下文菜单。这就是你通常如何定义没有功能的contextmenu:

"contextmenu" : { 
     items: { 
      "some_action" : { 
       "label" : "Do something", 
       "action"   : function (obj) { this.do_action(obj); }, 
       "_disabled"   : function (obj) { 
        // here you can decide if you want to show the item but disable it 
       } 
      }; 
      // define more items 
     }; 
     if (data.rslt.o.attr("rel") == "no_action") { 
      delete items.some_action; 
     } 
    return items; 
} 
+0

设置_disabled:function(){...}对我很好,谢谢。 – JayCrossler 2014-10-23 18:24:50

相关问题