I have to show only selected nodes and parents, and hide rest nodes when a button is clicked. Only nothing happens when I click the button.
The jsfiddle
The code with commenting
start on button click
$('button[name="psychTree-selected"]').click( function(node) {
get the selected nodes
nodesSelected = $('#psychTree').tree('getSelectedNodes');
create an array for shown nodes
nodeIdsToStay = [];
walk through selected nodes
nodesSelected.forEach( function(node) {
var path = $('#psychTree').tree('getData');
path.forEach(function(n) {
if (nodeIdsToStay.indexOf(n)===-1) {
nodeIdsToStay.push(n);
}
})
})
hide the nodes not in the array
$('#psychTree').find('li').each( function(){
if ( nodeIdsToStay.indexOf(this.id) === -1 ) {
$(this).hide();
}
})
})
I know how to hide the selected nodes but apparently non selected nodes do not have an identifiable class for me to search and hide by http://jsfiddle.net/tom1nkfr/
`$('button[name="psychTree-selected"]').click( function() {`
`$('#psychTree').find('.jqtree-selected').each( function(){`
`$(this).hide();`
`})`
`})`