前端:jsTree API

基本用法:

$('#tree1').jstree(); // creates an instance
$('#tree2').jstree({ plugins : [] }); // create an instance with some options
$('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments
$('#tree2').jstree(); // get an existing instance (or create an instance)
$('#tree2').jstree(true); // get an existing instance (will not create new instance)
$('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method)

注册事件:

.on("changed.jstree", function(e, data){
    if(data.selected.length) {
        alert('The selected node is: ' + data.instance.get_node(data.selected[0]).text);
        alert(data.node.id);
    }
});

$.jstree.defaults.core.check_callback 控制所有改变树结构的交互操作是否可执行,true可执行

//复制一个树到另一个树     
$("#debug").click(function(){
    var tree = $('#html').jstree();
    var t = tree.get_json("j1_1");
    var newtree = $.jstree.create(
        $("#newtree"),
        { 'core' : {
            //'check_callback': true,
            'data' : t
        }}
    );
});
posted @ 2019-01-11 09:33  xuejianbest  阅读(687)  评论(0编辑  收藏  举报