1

是否可以捕获对 jstree 上下文菜单项的单击?

我从json的文件中加载了一个这样的上下文菜单

{
    "item1" : {
        "label" : "item 1",
        "action" : "function(){alert('item 1')}"

     },
    "item2" : {
        "label" : "item 2",
        "action" : "function(){alert('item 2')}"
    }
}

我想捕获对上下文菜单项的单击,以评估函数并执行它。有可能做这个吗?

4

1 回答 1

0

我是这样解决的:

$("#tree").jstree({ 
    "plugins" : [ "json_data"],
    "json_data" : {
        "ajax" : {
        "type": 'GET',
         "url": "json_data.json";
         "success": function (new_data) {   
                  return new_data;
          }
         }
       },
       "contextmenu" : {
        "items" : customMenu
        }
});


function customMenu(node) {
    var items = {};

    $.ajax({
       url: "contextmenu.json",
       dataType: 'script',
       async : false,
       success : function( script ){    
           eval(script)
           items = menuItems;                   
       } 
    });

    return items;
} 



// file: "contextmenu.json"
var menuItems = {
    "item1" : {
        "label" : "item 1",
        "action" : function(){alert('item 1')}

     },
    "item2" : {
        "label" : "item 2",
        "action" : function(){alert('item 2')}
    }
}
于 2012-04-20T21:20:19.810 回答