javascript - Problem with "initially_open" option with JStree -
i'm working on first app using jstree , have doing need navigation tree. have javascript code working dynamically builds html list structure page using knockoutjs (somewhat of overkill here, use knockout elsewhere on page). after attach jstree html, dom looks likes -
<div id="menutreelist" data-bind="template: "treemenutemplate"" class="navtree jstree jstree-0 jstree-focused jstree-default"> <ul class="jstree-no-dots jstree-no-icons"> <li id="menu_1" class="jstree-leaf"><ins class="jstree-icon"> </ins><span> <a href="#" class=""><ins class="jstree-icon"> </ins>cares home</a></span> </li> <li id="menu_2" class="jstree-closed"><ins class="jstree-icon"> </ins><a href="#"> <ins class="jstree-icon"> </ins>case management</a> <ul> <li id="menu_3" class="jstree-leaf"><ins class="jstree-icon"> </ins><span class="navtree-spandefault"> <a href="#"><ins class="jstree-icon"> </ins>search</a></span> </li> <li id="menu_4" class="jstree-leaf"><ins class="jstree-icon"> </ins><span class="navtree-spandefault"> <a href="#"><ins class="jstree-icon"> </ins>participant summary</a></span> </li> <li id="menu_5" class="jstree-leaf"><ins class="jstree-icon"> </ins><span class="navtree-spandefault"> <a href="#"><ins class="jstree-icon"> </ins>transfer wp office</a></span> </li> <li id="menu_6" class="jstree-last jstree-leaf"><ins class="jstree-icon"> </ins><span class="navtree-selected">update individual address</span> </li> </ul> </li> <li id="menu_7" class="jstree-last jstree-leaf"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>tools</a></li> </ul> </div>
my javascript invokes jstree
$(document).ready(function () { $("#menutreelist").jstree({ "themes": { "theme": "default", "dots": false, "icons": false }, "plugins": ["themes", "html_data"], "core": { "animation": 0, "open_parents": true, "initially_open": ["menu_5"] } }); })
the resulting menu looks
my problem want menu have nodes closed, open node represents current page "selected" , it's parent nodes opened. when try setting jstree "initially_open" "menu_5" or "menu_6", menu displays closed.
long term, going complicated & multi-level structure. users looking type of functionality. suggestions?
use initially_select
(instead of initially_open
) option (ui section): set unique id
leaf-node (like 'init_sel') , set option in ui section of jstree constructor:
"ui" :{ "initially_select" : ["#init_sel"] }
don't forget add "ui" in plugin list.
if use json_structure
data, set "state" object on parent node(s) "open" when generate json structure.
Comments
Post a Comment