vakata / jstree

jquery tree plugin
http://jstree.com
MIT License
5.13k stars 1.39k forks source link

load_node raises error and not load/display selected node in normal execution mode but works in debug mode #2731

Closed moghazali closed 12 months ago

moghazali commented 1 year ago

With reference to issue and solution here: https://github.com/vakata/jstree/issues/957#issuecomment-70213803

I know this is an old thread but I am not able to find solution to my problem elsewhere. I have implemented this and similar code example for lazy loading all the parents of a selected node.

Here is my code sample:

$('#divFoldersTree').on('loaded.jstree', function ()
{
  var folderId = document.getElementById("hdnFolderId").value;
  var initialFolderPath = document.getElementById("hdnInitialFolderPath").value;

  loadAndSelectInitialNode(folderId, initialFolderPath.split(","));
});
function loadAndSelectInitialNode(folderId, folderPaths)
{
  $('#divFoldersTree').jstree(true).load_node(folderPaths, function ()
  {
      this.select_node(folderId);
  });
}

The above code produces below errors when executed in normal mode and shows only root node:

Uncaught TypeError: Cannot read properties of undefined (reading 'id') at E.jstree.plugins.search.redraw_node (jstree.min.js:3:35797) at E.jstree.plugins.search.redraw_node (jstree.min.js:3:106557) at E.jstree.plugins.search.redraw_node (jstree.min.js:3:124768) at E.jstree.plugins.search.draw_children (jstree.min.js:3:34617) at E.jstree.plugins.search.open_node (jstree.min.js:3:39181) at E.jstree.plugins.search. (jstree.min.js:3:39922)

Uncaught TypeError: Cannot read properties of undefined (reading 'id') at E.jstree.plugins.search.redraw_node (jstree.min.js:3:35797) at E.jstree.plugins.search.redraw_node (jstree.min.js:3:106557) at E.jstree.plugins.search.redraw_node (jstree.min.js:3:124768) at E.jstree.plugins.search.draw_children (jstree.min.js:3:34617) at E.jstree.plugins.search.open_node (jstree.min.js:3:39181) at E.jstree.plugins.search._open_to (jstree.min.js:3:40225) at E.jstree.plugins.search.select_node (jstree.min.js:3:47070) at E.jstree.plugins.search. (DocsViewer.aspx?id=2727:883:13) at E.jstree.plugins.search._load_nodes (jstree.min.js:3:18273) at E.jstree.plugins.search.a (jstree.min.js:3:17992)

If I place a breakpoint at the data/AJAX call, I can see all calls to parents' nodes being made, json returned properly and ultimately the tree is loaded and specified node selected.

Am I doing something wrong or some kind of race condition is occurring somewhere that I'm not able to locate? Documentation and internet searches has not been of any help in this regard. Kindly help.

vakata commented 1 year ago

Sorry, but I can not help you without further information - what is your config? The error seems to come from the search plugin, but the quoted functions do not exist. Can you provide your full config and jstree version?

vakata commented 12 months ago

Will reopen when more information is available.