jstree Snippets

var tree = SentenceTree.getInstance();
var inst = $.jstree.reference(data.reference);

tree.get_selected();
tree.get_node(nodeid);
tree.get_children(node);
tree.get_path(id, false, true); // path ids as array
tree.delete_node(node);
tree.delete_node(node);

tree.select_node(node, true, false); // supress_event

tree.is_selected(obj)
tree.deselect_all();
tree.refresh(true, false)

$(this.ele).jstree(true).get_json('#', {flat:false, no_state:true});

//open
.tree.jstree('open_node', id, function(){ 
    .tree.jstree('select_node', selected_id, true, false); // select_node without event trigger 
});
// load
.tree.jstree('load_node', id, function(){
    //open
    .tree.jstree('open_node', id, function(){
        // select node. events nicht auslösen
        .tree.jstree('select_node', id, true, false);
    });
});

// create
tree.create_node(node, {
    'type':'placeholder', 
    'text': v
}, "last", function (new_node) {
////                setTimeout(function () { 
////                    //new_node.text = SentenceBuilder.wording.new_placeholder;
////                    inst.edit(new_node);
////                }, 0);
});

destroy

 

Debug

$('#tree1').jstree('destroy', '#tree1');

console.log($.jstree);

 

Contextmenu

// Contextmenü ausblenden
$('.vakata-context').hide();

 

Event Handler

this.tree.on('dblclick.jstree', function(event){
	that.onNodeDblClick(event); 
}); 
this.tree.on('changed.jstree', function(e, data){
   console.log('data', data);
	switch(data.action){
		case 'select_node':
			that.onNodeSelect(e, data) ; 
			break;
			
		case 'deselect_all':
			that.onNodeDeselectAll(e, data); 
			break;
			
		default:
			console.log('onNodeChanged with action', data.action, data.selected);
			break;
	}
});
this.tree.on('copy_node.jstree', function(e, data){ 
	that.onNodeCopy(e, data);
}); 
this.tree.on('create_node.jstree', function(e, data){ 
	that.onNodeCreate(e, data);
}); 
this.tree.on('move_node.jstree', function(e, data){ 
	that.onNodeMove(e, data);
}); 
this.tree.on('rename_node.jstree', function(e, data){ 
	that.onNodeRename(e, data);
}); 
this.tree.on('delete_node.jstree', function(e, data){ 
	that.onNodeDelete(e, data);
});  
this.tree.on('contextmenu.jstree', function(e, data){ 
	console.log('contextmenu.jstree')
});  
$(document).on('context_show.vakata', function(e, data){ 
	console.log('context_show.vakata')
});  
$(document).on('context_hide.vakata', function(e, data){ 
	console.log('context_hide.vakata')
});  

Folgende Artikel könnten auch interessieren