最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jsTree create_node callback function not working - Stack Overflow

programmeradmin5浏览0评论

Using jsTree, when adding a node to my tree using the create_node function, I am attempting to add a callback function, as per .1.0/dist/jstree.js#L3549 .

However, it does not seem to execute, as illustrated here--> / when Add Root Item is clicked (expecting console.log() to say "hi", in the very least).

Any idea what I may be doing wrong?

Using jsTree, when adding a node to my tree using the create_node function, I am attempting to add a callback function, as per https://github./vakata/jstree/blob/v.1.0/dist/jstree.js#L3549 .

However, it does not seem to execute, as illustrated here--> http://jsfiddle/thapar/e3nMg/ when Add Root Item is clicked (expecting console.log() to say "hi", in the very least).

Any idea what I may be doing wrong?

Share Improve this question edited Apr 19, 2012 at 14:02 Raj asked Apr 8, 2012 at 14:08 RajRaj 1,5713 gold badges15 silver badges30 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

jstree version 3, there is a create_node event:

"triggered when a node is created":

http://www.jstree./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");
    });
})

Per the documentation at http://www.jstree./documentation/core, it looks like the 'callback' parameter to the .create_node function is used internally. It states that you should instead listen for the event. You can do so like this (assuming you're using the same code as in your JSFiddle post:

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

发布评论

评论列表(0)

  1. 暂无评论