jQuery('foo').jstree(true) does not find the instance!?

745 views
Skip to first unread message

Gert

unread,
Apr 30, 2014, 10:13:24 AM4/30/14
to jst...@googlegroups.com
Hello,

I really have a strange problem. I am implementing an Web-App
 that includes two jstree instances on one page. Both trees are 
set up and work fine.

No I need to call refresh() on one these trees. The first one is found 
and refreshed ok. But for the second one jstree(true) just returns false.

What could be the problem? I really do not have an idea where to start debugging. 

Because the app is a little complex including iframes that invoke javascript 
functions in the top document it is difficult to extract the code and build an
example.

Both trees use the same init-Code for setting them up. The second tree (#bookmark_list), that 
cannot be found, is defined like this:

<div id="treeview"></div>   <!-- The first treeview -->
...
<div id="bookmark_list" data-jstree-content="bookmark"></div> <!-- the second one -->
...

 element_selector = 'div#bookmark_list';
...
  var $element            = jQuery(element_selector);

        jstree_instance = $element.jstree({
            'core' : {
                "multiple" : false,
                "animation" : 60,
                'themes'    : {
                    'dots': true,
                    'stripes': false
                },
                'data' : {
                    type: "POST",
                    'url' : dispatcher_url + '/PageJSTree/load_node/' + ticket,
                    'data' : function (node) {
                        var opened = [current_root_oid];
                        this.get_node(node, true).find('.jstree-open').each(function () { opened.push(this.id); });
                        
                        // content describes which tree will loaded
                        var jstree_content = $element.attr('data-jstree-content');

                        return {
                            "id":       node.id,
                            "root_oid": current_root_oid,
                            "content":  jstree_content,
                            "opened":   opened
                        };
                    }
                }
            }

This works fine so far.

But after this I am not able to refresh this instance. I have tried many things like:

jstree_instance.refresh();
jQuery(element_selector).jstree(true).refresh();

but I get the error that "refresh is not a function".


For debugging I put in some console.log calls:

console.log('container_selector');
console.log(container_selector);

console.log("jQuery(container_selector)");
console.log(jQuery(container_selector));

console.log("jQuery(container_selector).jstree(true)");
console.log(jQuery(container_selector).jstree(true));

jQuery(container_selector).jstree(true).refresh();


And I get the output:

Ivan Bozhanov

unread,
Apr 30, 2014, 11:40:30 AM4/30/14
to jst...@googlegroups.com
Although this should not interfere, try removing: data-jstree-content="bookmark"
Also - try running this in the console: jQuery('[id="bookmark_list"]') - you may have two DIVs with the same ID, and only one of them with an instance.

Try those two suggestions and tell me how it went so that I can help you further, because I cannot reproduce this.

Best regards,
Ivan

Gert

unread,
Apr 30, 2014, 12:00:53 PM4/30/14
to jst...@googlegroups.com


Am Mittwoch, 30. April 2014 17:40:30 UTC+2 schrieb Ivan Bozhanov:
Also - try running this in the console: jQuery('[id="bookmark_list"]') - you may have two DIVs with the same ID, and only one of them with an instance.

OMG! I am very sorry for letting you debug my code. Indeed it was this fault. I had an obsolete

   <script type="text/template" id="bookmark_list">

somewhere else in my HTML code that certainly did interfere! Removed this and everything works! I feel so blind. :(

Sorry again and thank you very much for this hint.

Gert

Ivan Bozhanov

unread,
Apr 30, 2014, 1:02:06 PM4/30/14
to jst...@googlegroups.com
No problem :) I am glad it is working now.

Cheers,
Ivan
Reply all
Reply to author
Forward
0 new messages