OdinaSpb / jstree

Automatically exported from code.google.com/p/jstree
0 stars 0 forks source link

Supress initial ajax load on existing DOM tree (with "html_data" plugin) #911

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We're planning to use jsTree in SilverStripe CMS (www.silverstripe.org) -
its exciting to see a jQuery-based library with this much sophistication!

From what I understand, the "html_data" plugin allows you to define
the "ajax" parameter without specifying a "data" HTML string
(Example "Using both the data & ajax config options" on 
http://www.jstree.com/documentation/html_data).

In our case, the CMS does an initial (partial) render of the first two tree 
levels
in the page markup (not through "data" parameter), which should be sufficient 
to initialize the tree.
At the moment, jsTree ignores this existing markup and reloads the whole tree 
via ajax.

Looking at load_node_html() in the plugin, the last case() condition doesn't
check if the node is already loaded, which would be the case (_is_loaded(-1)).
I assume load_node_html() should reload regardless of the current state?
If thats the case, can the _is_loaded() check sit somewhere earlier to avoid 
this?

I've attached a sample HTML tree, here's my init:

$('#sitetree_ul').jstree({
    'html_data': {
        'ajax': {
            'url': 'admin/getsubtree',
            'data': function(node) {
                return { ID : $(node).data("id") ? $(node).data("id") : 0 , ajax: 1};
            }
        }
    },
    'plugins': ['themes', 'html_data']
});

Original issue reported on code.google.com by ingo.sch...@gmail.com on 28 Feb 2011 at 5:15

Attachments:

GoogleCodeExporter commented 9 years ago
Here's a patch for the switch() statement in load_node_html() which fixes this. 
Its in git format-patch format, so you have to apply with "patch -p1" instead 
of "patch -p0".

It also adds some explanations on the different switch conditions. Not sure if 
I've got the "root node" part right - what are you implying with "!obj && obj 
== -1" ?

Original comment by ingo.sch...@gmail.com on 10 Mar 2011 at 8:08

Attachments: