jstree

jsTree: How to *set* opened/selected node by path (not ID)?


So, I can get the full path of a selected node like so (thanks to @ggrandes for that one):

.on('changed.jstree', function (e, data) {
  var path = data.instance.get_path(data.node,'/');
  console.log('Selected: ' + path); 
})

What I now need, is to set select/open a node according to a given path.

All the solutions I've found so far refer to some mysterious ID, which appears to simply assume that the data in question has IDs. My problem is that I don't. It's simply a recursive JSON dict/array describing a directory layout. All I have with each node, is its name and a list of its children (and their names and children and so forth).

So, what I need is something like:

data.instance.set_path('/some/arbitrary/path');

Is it possible to do this with jsTree in some reasonable way?


Solution

  • I ended up creating a full path of every item on the server-side and using that as an ID that could then be selected on the client-side. As far as I can tell, there is no other way, at the time of this writing.