title: Jstree: Cannot read property children of undefined. Timing issue?
body: <p>I have an array of objects where each of them look like this structure:</p>
  
  <pre><code>var data = [{
  "code" : "i1",
  "name" : "Industry 1",
  "parentCode" : "i0"
  }, 
  {
  //and more items just like that one
  }];
  </code></pre>
  
  <p>so I am using <code>jstree</code> to build a hierarchy view. Since <code>jstree</code> needs <code>id</code> and <code>text</code>, I map the <code>data</code> array like this:</p>
  
  <pre><code>datatree = $.map(data, function (item) {
  
          return {
              id : item.code,
              text : item.name,
              parent : item.parentCode
  
          };
  
      });
  </code></pre>
  
  <p>And then I initialize the actual tree inside my <code>hierarchy</code> div:</p>
  
  <pre><code>$('#hierarchy').jstree({
  
      "core": {
          "themes": {
              "variant": "large"
          },
          "data": datatree,
      },
      'check_callback': true,
      "checkbox": {
          "keep_selected_style": false
      },
      "plugins": ["wholerow", "search", "unique"]
  });
  </code></pre>
  
  <p>This builds the tree and works fine when the original array is pretty simple, maybe one or two levels deep of parentages. However, if I test with an alternative array build exactly the same way, but with 5 levels of parentages, the console throws an error:</p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'children' of undefined
  </code></pre>
  
  <p>And it's pointing to this row in the <code>jstree</code> original code:</p>
  
  <pre><code>k[c[o].parent.toString()].children.push(c[o].id.toString()),
  </code></pre>
  
  <p>I have the suspicion that it's a timing issue, as in <code>jstree</code> being unable to build the children array because there are still pending items to load. But I might be wrong in my assumption. </p>
  
  <p>How can it be that the code works perfectly for arrays with simple parentages, but it breaks when there are multiple parent levels? Is it just timing as I guess, or there might be deeper issues?</p>
  
  <p>I have read <a href="https://stackoverflow.com/questions/25184210/jstree-uncaught-typeerror-cannot-read-property-children-of-undefined">this question</a>, but it seems that the user was initially working with AJAX and solved the problem declaring a local object. Mine is already local and it actually works in some cases, so I am not sure what's going on.</p>