You should use select_node
and deselect_node
as below. If you want to check and select a node separately, you need to set the tie_selection
param of checkbox plugin in the tree config as false and select/deselect a node manually.
Check demo - Fiddle Demo
$("#jstree")
.jstree({
core: {
data: coredata,
check_callback: true
},
plugins: ["checkbox"],
checkbox: {
tie_selection: false
}
})
.on("select_node.jstree deselect_node.jstree", function(e, data) {
subfunction(data);
})
.on("check_node.jstree uncheck_node.jstree", function(e, data) {
subfunction2(data);
});
function subfunction(data) {
//some operation;
alert('You got me selected: ' + data.node.state.selected)
};
function subfunction2(data) {
//some operation;
alert('You got me checked: ' + data.node.state.checked);
// now you need to decide what you want to select or not
// and do it manually, e.g. like below
var selectFlag = true;
if (selectFlag) {
var action = data.node.state.checked ? 'select_node' : 'deselect_node';
$("#jstree").jstree(action, data.node);
}
};