防止jsTree节点选择 [英] prevent jsTree node select

查看:445
本文介绍了防止jsTree节点选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the jsTree plugin to list folders in the file system. I need to prevent a user from changing to another node before a certain condition is met.
The below code does not stop the propagation... i saw some solutions with other plugins but this is a simple task it must be possible without other plugins.

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

推荐答案

本人和后人的文档:加载jstree JS之后,您需要包括以下功能(来自:

Documenting for myself and posterity: you need to include the following function AFTER loading the jstree JS (from: 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实例时执行以下操作:

Then when initializing an instance of jstree do something like this:

$('#jstree').jstree({
  'conditionalselect' : function (node) {
    return <something that determines condition> ? true : false;
  },
  'plugins' : ['conditionalselect'],
  'core' : {
    <core options>
  }
});

这篇关于防止jsTree节点选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆