jsTree create_node回调函数不起作用
问题描述:
使用jsTree,当使用create_node
函数向我的树添加节点时,我试图添加一个回调函数,根据https://github.com/vakata/jstree/blob/v.1.0/dist/jstree.js#L3549。jsTree create_node回调函数不起作用
然而,它似乎并没有执行,如下所示 - >http://jsfiddle.net/thapar/e3nMg/当点击Add Root Item
(预期console.log()
说“嗨”,在最低限度)。
任何想法我可能做错了什么?
答
根据http://www.jstree.com/documentation/core的文档,它看起来像.create_node
函数的“回调”参数在内部使用。它表示,你应该倾听该事件。你可以这样做(假设你使用相同的代码在你的JSFiddle帖子:
$('.colors').bind('create_node.jstree', function (e, data) {
console.log('hi', data.rslt.obj);
});
答
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");
});
})