【问题标题】:jsTree create_node callback function not workingjsTree create_node 回调函数不起作用
【发布时间】:2012-04-08 14:08:45
【问题描述】:

使用 jsTree,当使用 create_node 函数将节点添加到我的树时,我正在尝试根据 https://github.com/vakata/jstree/blob/v.1.0/dist/jstree.js#L3549 添加回调函数。

但是,它似乎没有执行,如此处所示--> 当单击 Add Root Itemhttp://jsfiddle.net/thapar/e3nMg/ (至少希望console.log() 说“嗨”) .

知道我做错了什么吗?

【问题讨论】:

    标签: javascript jquery jquery-plugins jstree


    【解决方案1】:

    jstree版本3,有create_node事件:

    “创建节点时触发”:

    http://www.jstree.com/api/#/?q=.jstree%20Event&f=create_node.jstree

    $(function() {
        var $root = $('#jstree').jstree({
            "core" : {
                check_callback : true
            },
            "themes" : {},
            "ui" : {},
            "plugins" : [ "dnd", "state","themes", "html_data", "ccrm", "ui" ],
    
        });     
    
        $('#jstree').on('create_node.jstree', function(e, data) {
            console.log('hi', data);
        });
    
        $('#add_root').click(function() {
            $root.jstree(true).create_node($root, "sub4");
        });
    })
    

    【讨论】:

      【解决方案2】:

      根据http://www.jstree.com/documentation/core 的文档,看起来.create_node 函数的“回调”参数在内部使用。它指出您应该改为侦听该事件。您可以这样做(假设您使用的代码与 JSFiddle 帖子中的代码相同:

      $('.colors').bind('create_node.jstree', function (e, data) {
         console.log('hi', data.rslt.obj);
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-20
        相关资源
        最近更新 更多