防止jsTree节点选择

我正在使用jsTree插件列出文件系统中的文件夹。 我需要阻止用户在满足特定条件之前更改到另一个节点。
下面的代码并没有停止传播…我看到了其他插件的一些解决方案,但这是一个简单的任务,必须可以没有其他插件。

$('#jstree').on('select_node.jstree', function (e) { if (!changeAllowed() { e.preventDefault(); e.stopImmediatePropagation(); } }); 

为自己和后代记录:在加载jstree JS之后需要包含以下function(来自: https : //github.com/vakata/jstree/blob/master/src/misc.js ):

 // jstree conditional select node (function ($, undefined) { "use strict"; $.jstree.defaults.conditionalselect = function () { return true; }; $.jstree.plugins.conditionalselect = function (options, parent) { // own function this.select_node = function (obj, supress_event, prevent_open) { if(this.settings.conditionalselect.call(this, this.get_node(obj))) { parent.select_node.call(this, obj, supress_event, prevent_open); } }; }; })(jQuery); 

然后在初始化jstree的实例时执行以下操作:

 $('#jstree').jstree({ 'conditionalselect' : function (node) { return  ? true : false; }, 'plugins' : ['conditionalselect'], 'core' : {  } });