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 badges2 Answers
Reset to default 4jstree 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);
});