Jstree: Cannot read property children of undefined. Timing issue?

That error happens with me when, in your code:

{
  id : item.code,
  text : item.name,
  parent : item.parentCode
};

Your parent has an id of to a non-existent item. The parent key must exist, and won't accept false, null, 0, or an id that isn't in the data list. If an item has no parent, the parent needs to be "#", i.e. "parent": "#".

So:

  • Check items with parent null or undefined;
  • Check items with parent without corresponding parent