My tree container is <div id="getStartedTree">
My jsTree code
$("#getStartedTree").jstree({
"themes": {
"theme": "default",
"url": "../App_Css/Themes/Default/style.css",
"dots": true,
"icons": true
},
"json_data": {
"ajax": {
"url": "../SiteMaps/TextFile.txt",
"dataType": "json",
"data": function(n) {
return { id: n.attr ? n.attr("id") : 0 };
}
}
},
"plugins": ["themes", "json_data", "ui"]
});
The JSON in the TextFile.txt - borrowed from your simple example
[
{
"data" : "A node",
"children" : [ "Child 1", "Child 2" ]
},
{
"attr" : { "id" : "test1" },
"data" : {
"title" : "Long format demo",
"attr" : { "id" : "test2", "href" : "#" }
}
}
]
The tree will populate as expected
Here's the select_node Binding - where I redirect to a new page. Also
note I use the "cookies" not "cookie" plugin in my project. so I was
not able to use your jstree functionality for state management. My
work around would be to set a cookie for the node that was selected.
My page then redirects to the new page, and I would read the cookie,
and programmatically select the node.
$("#getStartedTree").bind("select_node.jstree", function(event, data)
{
var href = data.rslt.obj.attr("href");
var path = window.location.href.toLowerCase();
//$.cookies.set('selectedNode', selectedNode);
var loc = path.indexOf('mywebsite');
loc = loc + 10; // mywebsite/ char count
var root = path.substring(0, loc);
window.location.href = root + href;
});
I was then attempting to read the cookie, get its selected value, so
that I could programmatically select.
thus first I was just trying to something like this, which I basically
try and select test2.
In firebug I see that the the ids "test1" is for a list item, and
"test2" for the anchor.
jQuery($("#getStartedTree")).jstree("select_node", $("#test2"));
Upon programatic selection I would then expect to see it styled blue,
however it always seems as if nothing is selected.
This failed, and I tried a slew of "desperation" variations, however I
could not figure it out....then I asked for help, then I tried to get
your solution to work. Unfortunately I was still unsuccessful. : (
I hope I'm not doing something incredibly stupid that I'll be totally
embarrassed over..
I REALLY appreciate your help! : )