【问题标题】:How can I create a child node by selecting a parent node using jstree?如何通过使用 jstree 选择父节点来创建子节点?
【发布时间】:2020-08-04 11:32:23
【问题描述】:

这是我第一个使用 jQuery 的项目。

我已经使用 jstree 创建了父节点。当用户单击任何父节点时,我希望在相应的父节点中创建一个子节点。

$(function(){
    $('#container').on('click', function(){

        var newNode = { data: "Child1" };
        var parentNode = $('#container').jstree('get_node', event.target.id); 
        $("#container").jstree(true).create_node(parentNode, newNode, "last");
        
    })
})

【问题讨论】:

    标签: javascript jquery jstree


    【解决方案1】:

    容器点击事件不会给你选择的节点。 jsTree API 对此有特定的事件。您应该使用select_node.jstree 事件来识别节点选择。

    $("#container").bind("select_node.jstree", function (e, data) {
        var newNode = { data: "Child1" };
        $("#container").jstree(true).create_node(data.node.id, newNode, "last");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-10
      • 1970-01-01
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多