2014-10-28 25 views

回答

1

這幾乎沒有訣竅。

$("#housingTree").jstree({ 
      "plugins": ["themes", "html_data", "ui", "crrm", "hotkeys", "contextmenu"], 

      "core": { "initially_open": ["phtml_1"] }, 


      "contextmenu": { 
       "items": function ($node) { 

        return { 
         "Rename": { 
          "label": "Rename", 
          "action": function (obj) { this.rename(obj); } 
         }, 
         "Create": { 
          "label": "Create", 
          "action": function (obj) { this.create(obj); } 
         }, 
         "Delete": { 
          "label": "Delete", 
          "action": function (obj) { this.remove(obj); } 
         }, 
         "Cut": { 
          "label": "Cut", 
          "action": function (obj) { this.cut(obj); } 
         }, 
         "Paste": { 
          "label": "Paste", 
          "action": function (obj) { this.paste(obj); } 
         } 
        }; 
       } 
      } 
     }) 
1

我不知道如果動作函數是默認函數或自定義函數,但那不適合我......反正你的文章確實讓我在正確的路徑!謝謝!

這是我做的,找到另一篇文章後:

"contextmenu": { 
     "items": function ($node) { 
      var tree = $("#html1Tree").jstree(true); 
      return { 
       "Rename": { 
        "label": "Rename", 
        "action": function (obj) { 
         tree.edit($node); 
        } 
       }, 
       "Create": { 
        "label": "Create", 
        "action": function (obj) { 
         $node = tree.create_node($node); 
         tree.edit($node); 
        } 
       } 
      }; 
     } 
    } 

jsTree and Context Menu: modify items

1

較短的做法可能是

"contextmenu": { 
    "items": function(node) { 
      var defaultItems = $.jstree.defaults.contextmenu.items(); 
      console.log("default items : "+JSON.stringify(defaultItems)); 
      delete defaultItems.ccp.submenu.copy; 
      return defaultItems; 
     } 
    }, 

可以CONSOLE.LOG(defaultItems)。它將打印對象的json表示。您也可以修改其他屬性。