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?
We’re probably having the same problem. Add the following code to your jstree
cookiesconfig:cookies: { cookie_options: { path: '/' } }so you’ll have a tree config similar to this:
What’s going on?
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 idlocalhost_homehttp://localhost/Admin/with node idlocalhost_adminand you want to navigate from
http://localhost/Home/tohttp://localhost/Admin/by clicking on thelocalhost_adminnode, you’re probably expecting that by the time you get tohttp://localhost/Admin/thejstree_selectcookie will havelocalhost_adminselected right?What really happened here is that 2 separate cookies now exist. One for
http://localhost/Home/and another forhttp://localhost/Admin/containing 2 separate values.By setting the path option to
/, we’re ensuring that only 1 cookie gets shared across all pages.