2012-03-09 14 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" : { 
     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

関連する問題