3

until now I've been using jQuery TreeView for my website's navigation menus, but now since the main navigation menu (on the left pane) has grown too large (Vim reports it takes 40869 bytes out of a typical page's 67054 bytes) I would like to make it less comprehensive in the raw HTML, and populate the remaining parts using AJAX calls that fetch JSON.

However, jQuery Treeview cannot do that (and its author claims it is incomplete), so I'm looking into jqTree. jqTree seems to be able to handle AJAX stuff, but I don't understand from the documentation how I can get it to read an initial tree skeleton from some <ul><li> tags in the HTML, which I want to keep for people whose browsers don't support JavaScript or block it by default (I am using NoScript to blacklist all domains my default and am often irritated that sites don't even display correctly without JavaScript).

I suppose I can write some jQuery code to traverse the <ul><li> structure recursively using jQuery's DOM support and construct some JSON out of it (with some amount of difficulty), but I'm wondering if it is a solved problem?

Thanks in advance,

— Shlomi Fish

Shlomi Fish
  • 4,380
  • 3
  • 23
  • 27

1 Answers1

2

Jqtree does not support getting the data from html.

I think that the best way to support browsers without javascript is to generate the tree in html AND initialize a tree with json data. That of course means more work for you. You have to generate the html and the json data.

Jstree, another tree component, does support this. See http://www.jstree.com/documentation/html_data.

  • Hi, thanks for the information. I ended up deciding to take a somewhat different approach of outputting my navigation menu data (represented as a nested Perl 5 data structure) to JSON and using AJAX to retrieve the common and static JSON file and processing it in the client-side to create a nested JavaScript for the tree. The initial tree in the plain HTML will only contain a subset of this, which should be usable for people without JS and for search engines/etc. Thanks, anyway. – Shlomi Fish Dec 16 '12 at 11:18