Note that there are some explanatory texts on larger screens.

plurals
  1. POJSTREE script execute asynchronously
    primarykey
    data
    text
    <p>I Have implemented <strong><a href="http://www.jstree.com/" rel="nofollow">JSTREE</a></strong> on my project everything work fine but recently I faced the issue which even though I manage to fix the concept of it is still unclear to me . </p> <p>Here What I meant ?</p> <p>the <strong>JSTREE</strong> Code is Written in <a href="http://jquery.com/" rel="nofollow">jquery</a> <strong>document ready function</strong> Like this</p> <blockquote> <pre><code>$(document).ready(function() { $("#someid").jstree( { "json_data" : { "data" : [{ "attr" : { "id" : "root" }, "data" : { "title" : "Root", "attr" : { "id" : "root","href" : "#" ,"class" : "jstree-clicked" } }, "children" : [ { "attr" : {"id" : "node-1"}, "data" : { "title" : "Node-1", "attr" : {"id" : "node-1" ,"href": "#" } }, "children": [ ], "state" : "closed" }, { "attr" : {"id" : "node-2"}, "data" : { "title" : "Node-2", "attr" : {"id" : "node-2" ,"href": "#" } }, "children": [ ], "state" : "closed" }, { "attr" : {"id" : "node-3"}, "data" : { "title" : "Node-3", "attr" : {"id" : "node-3" ,"href": "#" } }, "children": [ ], "state" : "closed" }, { "attr" : {"id" : "node-4"}, "data" : { "title" : "Node-4", "attr" : {"id" : "node-4" ,"href": "#" } }, "children": [ ], "state" : "closed" }, { "attr" : {"id" : "node-5"}, "data" : { "title" : "Node-5", "attr" : {"id" : "node-5" ,"href": "#" } }, "children": [ ], "state" : "closed" } ], // the method where the ajax request will be sent to get thejson data to build the tree "ajax" : { "url" : "/my_url/tree", "data" : function (focus_element) { return { node : focus_element.attr ? focus_element.attr("id") : 0 }; } } }, "themes" : { "theme" : "classic", "dots" : true, "icons" : true }, "plugins" : ["themes", "json_data" ,"ui"] }) </code></pre> </blockquote> <p>There is a <strong>another jquery document ready</strong> function on the page <strong>which will click the</strong> anchor node <strong>created but the above jstree</strong> .</p> <blockquote> <p>$(document).ready(function() {</p> <pre><code> $("a#node-1").click() </code></pre> <p>})</p> </blockquote> <p>Now The problem come when the page is load the tree is constructed all the tree is constructed but the <strong>node-1</strong> anchor link is not getting clicked . </p> <p>Debugging it I found That the <strong>console.log always present me and empty array</strong> for a#node-1 which is very weird. </p> <p>I put <strong>alert box in second document.ready function</strong> to see whether the tree is constructed when I'm requesting for the node. like this </p> <blockquote> <p>$(document).ready(function() { </p> <pre><code>alert("JSTREE SHOULD BE CREATED BY NOW"); $("a#node-1").click() </code></pre> <p>})</p> </blockquote> <p>But to my astonishment the when the <strong>alert popped up JSTREE was still build the tree .</strong> </p> <p>With some decent understanding of javascript I know that script tag on the page are <strong>synchronous in nature</strong> i.e the second script on the page execute only when the first execute</p> <p>This make me believe <strong>is JSTREE running asynchronously</strong> .If yes Can please any one share some light on it . </p> <p>By the Way I manage to achieve the same using <strong>jstree load handler</strong></p> <blockquote> <p>$("#someid").bind("loaded.jstree",</p> <pre><code> function() { $("a#node-1").click(); }) </code></pre> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload