Reputation: 13003
I'm using cookies plugin in my jsTree in order to remember and restore the last node the user clicked on.
The behavior of my tree is that on node's double-click i'm redirecting the client to appropriate page in my site.
I'm expecting the last double-clicked node to be highlighted after I was redirected but for some reason I must do the double-click again on the same node in order it to be highlighted, it's seems like it's highlighting the previous selected node instead of the last selected node.
Any idea?
Upvotes: 3
Views: 3000
Reputation: 4661
We're probably having the same problem. Add the following code to your jstree cookies
config:
cookies: { cookie_options: { path: '/' } }
so you'll have a tree config similar to this:
$('.my-tree').jstree({
plugins: ["html_data", "ui", "cookies"]
cookies: { cookie_options: { path: '/' } }
})
The reason for this is that if jQuery cookies (the library jstree uses to write its cookies) don't have their path set, the cookies will be stored relative to the current page you're on.
So, for example, if you have two nodes (also leaves/needles):
http://localhost/Home/
with node id localhost_home
http://localhost/Admin/
with node id localhost_admin
and you want to navigate from http://localhost/Home/
to http://localhost/Admin/
by clicking on the localhost_admin
node, you're probably expecting that by the time you get to http://localhost/Admin/
the jstree_select
cookie will have localhost_admin
selected right?
What really happened here is that 2 separate cookies now exist. One for http://localhost/Home/
and another for http://localhost/Admin/
containing 2 separate values.
By setting the path option to /
, we're ensuring that only 1 cookie gets shared across all pages.
Upvotes: 5
Reputation: 10305
have a look at the options like auto_save
cause i'm not sure when the jstree is saving the state of the jstree into the cookie. Maybe it doesn't when you double click
Upvotes: 0