【问题标题】:Jstree custom pluginJstree 自定义插件
【发布时间】:2019-11-15 16:34:11
【问题描述】:
我们有一个jstree 1.0-rc3 的项目。为了扩展基本功能,我们使用JQuery.jstree.plugin() 函数编写了自定义扩展。换句话说,我们创建了自定义插件并将其用作常用插件。最近我们决定将 jstree 版本更新到最新(3.3.8),我遇到了麻烦,因为这个函数(JQuery.jstree.plugin)不再存在,我找不到任何类似的。由于我们自定义插件的大小(数百行)和我们使用它的大量位置,我们不想将功能从自定义插件移动到另一个地方,因为这将花费大量时间。有谁知道如何在最新的jstree ( 3.3.8 now) 中创建自定义插件?非常感谢。
【问题讨论】:
标签:
javascript
jquery
tree
jstree
【解决方案1】:
在当前的 jsTree 版本 (3.3.8) 中仍然存在添加自定义插件的功能。作为例子,已经解释过了
// conditional select
(function ($, undefined) {
"use strict";
$.jstree.defaults.conditionalselect = function () { return true; };
$.jstree.plugins.conditionalselect = function (options, parent) {
this.activate_node = function (obj, e) {
if(this.settings.conditionalselect.call(this, this.get_node(obj))) {
parent.activate_node.call(this, obj, e);
}
};
};
})(jQuery);
$("#tree").jstree({
"conditionalselect" : function (node) {
return node.text === "Root node" ? false : true;
},
"plugins" : ["conditionalselect"]
});
请参考https://github.com/vakata/jstree#more-plugins 中解释的方法如何包含您自己的插件或任何第三方插件。您必须在页面上包含其源代码并在“插件”配置数组中列出其名称。
您可以查看 jstree/src/misc.js 以找到许多已经编写的此类自定义插件。