admin管理员组文章数量:1410717
I use 'contextmenu' and 'types' plugin in jstree and want to define different contextmenu according to the 'types', like this:
$("#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 } }
}
}
});
but it doesn't work, it displays the same contextmenu for all nodes, no specified one as I defined for 'leaf' nodes. Is it because cannot define contextmenu in type? Then how to achieve this easily.
I use 'contextmenu' and 'types' plugin in jstree and want to define different contextmenu according to the 'types', like this:
$("#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 } }
}
}
});
but it doesn't work, it displays the same contextmenu for all nodes, no specified one as I defined for 'leaf' nodes. Is it because cannot define contextmenu in type? Then how to achieve this easily.
Share Improve this question asked Mar 9, 2012 at 2:14 denceydencey 1,06117 silver badges25 bronze badges1 Answer
Reset to default 7You have to define the context menu in the context menu plugin section. I think the best way at the moment is to define all items for all nodes and then delete items according to the node type, or even better - define a function that returns the context menu according to the node. i.e, this is how you'd usually define the contextmenu without a function:
"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;
}
本文标签: javascriptHow to config contextmenu for different typs of nodes in jstreeStack Overflow
版权声明:本文标题:javascript - How to config contextmenu for different typs of nodes in jstree? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744838849a2627797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论