I use the jsTree library to display a tree of categories and subcategories on the ecommerce platform. When a node is clicked, I load a certain category with an ID added to the URL like this www.site.com/admin/catalog/categories/1
When I click, the page loads a new page, but no node is selected.
How to set selected node based on id or last selected node?
Here is my script
<script>
$(document).ready(function () {
var jstree = $('#jstree').jstree({
'core' : {
'data' : {
'url' : '/admin/catalog/categories',
'data' : function (node) {
return { 'id' : node.id };
}
}
}
});
jstree.on('changed.jstree', function (e, data) {
window.open('/admin/catalog/categories/'+data.node.id, '_self');
});
})
</script>
Are you still tired of writing procedures for selecting something? Here is the general procedure for selecting anything. You don't have to write another procedure for select anywhere. Try it, this is example: