使用jsTree,在使用 create_node
功能向我的树添加节点时,我正在尝试按照https://github.com/vakata/jstree/blob/v.1.0/dist/jstree.js#L3549添加回调函数。
然而,它似乎没有执行,如此处所示 - >单击 Add Root Item
时http://jsfiddle.net/thapar/e3nMg/ {期待console.log()
至少说“hi”。
知道我可能做错了吗?
答案 0 :(得分:3)
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");
});
})
答案 1 :(得分:1)
根据http://www.jstree.com/documentation/core的文档,看起来.create_node
函数的'callback'参数在内部使用。它声明你应该听取这个事件。您可以这样做(假设您使用的代码与JSFiddle帖子中的代码相同:
$('.colors').bind('create_node.jstree', function (e, data) {
console.log('hi', data.rslt.obj);
});