2012-03-09 71 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

相關問題