Javascript jstree检查和取消检查节点

Javascript jstree检查和取消检查节点,javascript,jquery,checkbox,jstree,Javascript,Jquery,Checkbox,Jstree,我想从我的jstree中获得两个独立数组中的选中节点和未选中节点 我已经看到了.get_checked和和

我想从我的jstree中获得两个独立数组中的选中节点和未选中节点

我已经看到了
.get_checked
函数,但是它们会将当前已检查和未检查的所有节点返回给我。(也就是说,如果一个节点未选中,而我没有选中它,那么我仍然使用
。get_unchecked
。我想防止这种情况发生)。我也准备对api进行重大更改。有什么方向吗


我可以获取复选框的更改事件吗。我也尝试过
change_state
,但这只适用于单击的一个节点。

据我所知,如果不重写jstree的checkbox插件,几乎不可能处理checkbox的单个事件,因为它们只是在每个check/uncheck事件上重新绘制单击文件夹的所有父节点和子节点

这里简单介绍一下:

一切都为我工作

HTML


这篇文章或其他文章的答案对我都不起作用,但找到了一种扫描节点和维护未检查项数组的方法

我的方法是首先以迭代方式获取所有节点的列表,然后引用其中的代码来获取节点列表(通过我自己的调整以递归方式迭代整个树,因为OP没有进入嵌套级别,而且我只需要ID)

然后我得到了一个li标签,它带有一个过滤函数,可以过滤所有点击的和未确定的项目,还有一个for循环,在这个循环中,我从以前检索到的主列表中删除了这些内容

$("#getUnchecked").bind("click", function () {

  //get a list of all nodes in the entire tree recursively - function in fiddle.
  ids = get_jstree_order('#tree > ul');

  var selNodes = $('li').filter(function () {
      //Find nodes that have jstree-clicked - or clicked items and
      //Find nodes that are undetermined
      return $(this).children('a.jstree-clicked').length
          || $(this).children('a').children('i.jstree-undetermined').length;
  });
  selNodes.each(function () {
      //find the position of the checked or undetermined id 
      let pos = ids.indexOf(this.id);
      //remove it from the master list, as we are filtering it down to just the unchecked ones
      ids.splice(pos, 1);
  })

  console.log(ids);
});

对于一个工作示例,请检查此处。

您可以提供任何代码吗?、使JSFIDLE plsin console:GET 404(Not Found)@DanStopka如果从最新版本中删除了GET_unchecked,您可以使用
$.Not()
来过滤已检查的节点,也可以使用
check_node
事件发生,因此我使用了
单击
事件
$(function() {
    var tree = $("#demo1").jstree({
        "plugins": ["themes", "html_data", "checkbox", "sort", "ui"]
    });
    tree.bind("open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree", function(e) {
        console.log("Event", e);
        console.log('Cheked:', tree.jstree('get_checked'));
        console.log('Uncheked:', tree.jstree('get_unchecked'));
    });
});​
$("#getUnchecked").bind("click", function () {

  //get a list of all nodes in the entire tree recursively - function in fiddle.
  ids = get_jstree_order('#tree > ul');

  var selNodes = $('li').filter(function () {
      //Find nodes that have jstree-clicked - or clicked items and
      //Find nodes that are undetermined
      return $(this).children('a.jstree-clicked').length
          || $(this).children('a').children('i.jstree-undetermined').length;
  });
  selNodes.each(function () {
      //find the position of the checked or undetermined id 
      let pos = ids.indexOf(this.id);
      //remove it from the master list, as we are filtering it down to just the unchecked ones
      ids.splice(pos, 1);
  })

  console.log(ids);
});