jstree官网:https://www.jstree.com.cn/api.html#/?f=toggle_node(obj)
jstree的GitHub地址:https://github.com/vakata/jstree,https://github.com/vakata/jstree/wiki
标题所说的操作就是要加插件,写法类似这个,也有点不一样
(function ($) {
"use strict";
//自己自定义图标,点这个图标出现contextmenu
var moreTools = document.createElement('a');
moreTools.className = "jstree-contextmenubtn btn btn-ssm btn-icon ml-4";
$(moreTools).append($("<i class='fas fa-ellipsis-v'></i>"))
$.jstree.plugins.contextmenubtn = function (_, parent) {
this.bind = function () {
parent.bind.call(this);
this.element
.on("click.jstree", ".jstree-contextmenubtn", $.proxy(function (e) {
e.stopImmediatePropagation();
$(e.target).closest('.jstree-node').children('.jstree-anchor').trigger('contextmenu');
}, this));
};
//拆卸
this.teardown = function () {
this.element.find(".jstree-contextmenubtn").remove();
parent.teardown.call(this);
};
this.redraw_node = function (obj, deep, callback, force_draw) {
obj = parent.redraw_node.call(this, obj, deep, callback, force_draw);
if (obj) {
var tmp = moreTools.cloneNode(true);
obj.insertBefore(tmp, obj.childNodes[2]);
}
return obj;
};
};
})(jQuery);
然后,在这里加上上面的名字,能实现这个功能了
其他操作
效果图:
大概就是这样,记录一下,希望能帮助到别人