【问题标题】:Capture tree node changed event捕获树节点更改事件
【发布时间】:2016-07-09 06:14:51
【问题描述】:

我正在使用jstree,并希望在选择节点时进行一些 ajax 调用。如果再次单击同一节点,我不想触发 ajax 调用。 jstree example for listening events 使用 changed.jstree 如下:

$('#jstree')
  // listen for event
  .on('changed.jstree', function (e, data) {
//my custom code here that should trigger if a new node is selected
});

但是,如果我两次单击同一节点,则会触发此问题。我在数据或事件对象 e 中找不到任何可以告诉我这是否与先前选择的节点相同的内容。 jstree中有什么可以帮助我解决这个问题吗?如果不是,那么解决这个问题的最佳方法是什么?

【问题讨论】:

    标签: javascript jstree


    【解决方案1】:

    我发现我们可以使用更改的插件来确定选中和取消选中的节点。这是显示的第一个插件here

    创建 jstree 并将 changed 包含在 plugins 数组中:

     $('#jstree').jstree(
                {
                    "core": {
                        "multiple": false,
                        // so that create works
                        "check_callback": true,
                        "data": menu
                    },
                    "plugins": ["changed"]
                }
        );
    

    如果选中和取消选中的数组都是空的,这意味着选择没有改变:

    $('#jstree').on('changed.jstree', function (e, data) {
      if (!(data.changed.selected.length === 0 && data.changed.deselected.length === 0))
      {
          //This is when something is really changed.
    });
    

    【讨论】:

      猜你喜欢
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      相关资源
      最近更新 更多