nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jqTree / _entries / 31_savestate.md
1 ---
2 title: saveState
3 name: options-savestate
4 ---
5
6 Save and restore the state of the tree automatically. Saves in a cookie which nodes are opened and selected.
7
8 The state is saved in localstorage. In browsers that do not support localstorage, the state is saved in a cookie.
9 For this to work, please include [jquery-cookie](https://github.com/carhartl/jquery-cookie).
10
11 For this to work, you should give each node in the tree data an id field:
12
13 {% highlight js %}
14 {
15     name: 'node1',
16     id: 123,
17     childen: [
18         name: 'child1',
19         id: 124
20     ]
21 }
22 {% endhighlight %}
23
24 * **true**: save and restore state in a cookie
25 * **false (default)**: do nothing
26 * **string**: save state and use this name to store in a cookie
27
28 {% highlight js %}
29 $('#tree1').tree({
30     data: data,
31     saveState: true
32 });
33 {% endhighlight %}
34
35 Example: save state in key 'tree1':
36
37 {% highlight js %}
38 $('#tree1').tree({
39     data: data,
40     saveState: 'tree1'
41 });
42 {% endhighlight %}