What is the process for expanding nodes in jstree with an array of identifiers?

I have been utilizing the jstree javascript plugin for loading data asynchronously. An essential feature I am working on is implementing search functionality for the tree's data. The process involves a web service that provides an array of ids following a search query. Notably, the tree is not loaded prior to performing a search. Upon user inputting a search query and triggering the function, I aim to gradually open nodes in the tree based on the respective ids obtained.

for(var i = 0; i < ids.length; i++){
     $("#tree").jstree("open_node", document.getElementById(ids[i]));
}

Despite my efforts, only the root node appears to load successfully. Could someone propose a straightforward solution for sequentially loading nodes using an array of ids?

I appreciate any assistance you can provide. Thank you.

Answer №1

In case the jsTree fails to load, you can specify "state" => "open" for the node that should be open when building data for jsTree. Take a look at the example below - extracted from

{
    "data" : "node_title",
    // exclude `attr` if unnecessary; the `attr` object is passed to the jQuery `attr` function
    "attr" : { "id" : "node_identificator", "some-other-attribute" : "attribute_value" },
    // `state` and `children` are only applicable for NON-leaf nodes
    "state" : "closed", // or "open", defaulting to "closed"
    "children" : [ /* an array of child nodes objects */ ]
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to pass optional properties to a Vue.js component in order to ensure they are effectively transmitted to the component?

There are recurring calls to a component from different views, like the example below: <highcharts :options="getSomeData" :constructor-type="'mapChart'" :callback="getSomeDataCallback" class=" ...

Is there a way to send an array of objects as parameters in JavaScript?

I have an array of objects with the same key name. My goal is to pass each address key inside those objects as a parameter to my API. How can I achieve this? The response I receive looks something like this: { '0': { address: 'abcd' }, ...

Tips for ensuring the drop down button remains selected

My goal is to keep the sorting drop-down button selected after clicking on it, instead of resetting back to "All". Below are my HTML, CSS, and jQuery code. You can view the functionality on my website here: jQuery/Javascript: $(document).ready(function($ ...

Issue with Tailwind classes not applying correctly upon refreshing the page in production settings

Challenge Description: Encountering an issue with my nextjs project that utilizes tailwindcss. The login page initially loads with the required classes for the UI, but upon refreshing the page, the classes disappear from the DOM, causing a broken UI. Her ...

Is it possible for npm to assist in determining the appropriate version of Primeng that is compatible with Angular 16 dependencies

While trying to add primeng to my project, I ran into an error message: npm i primeng npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__ ...

"Is there a way to retrieve "Lorem ipsum" information from a web service in JSON format

Does anyone know of any sample web services that serve JSON data? I'm looking to practice consuming JSON for testing and learning purposes. I would even be interested in downloading JSON files with images and other content to study offline. Perhaps th ...

Having trouble with my bootstrap carousel not functioning properly - issue with jQuery line causing the rest of the code to disable

I've been facing some challenges with this Bootstrap slider for quite some time now. Despite my best efforts and thorough research on the forum, I just can't seem to make it function properly. Here's the code snippet in question: <!DOCTY ...

The sequence of error middleware in Express4

Encountered a series of code execution that seemed unusual. Here's the code snippet: server.js const Actions_Single_PVC = require('./routes/Actions_single_PVC.js'); app.use('/Actions_single_PVC', Actions_Single_PVC); app.use((e ...

Tips on sorting ID strings that include a specific substring

I have a user input that may include a street, postal code, city, or a combination of them. How can I filter an array of objects to find those that contain any of these strings in the corresponding fields? getFilteredCentersSuggestions(searchTerm: string) ...

I have an array in JavaScript containing data objects within curly braces, and I want to disregard it

In trying to sum all values for each key in an array and create a new array with the key-total pairs, encountering difficulties when dealing with empty data represented by {}. To address this issue, attempting to validate that the data is not equal to {} b ...

Is your Javascript failing to update window.location.search?

Looking to update the URL search parameters when a user enters them in the search panel on a page. Currently attempting: $( document ).ready(function() { if ($('.o_website_license_search_panel').length) { $('.o_website_license_s ...

Dealing with substantial ajax responses using JavaScript

Currently, I am in the process of developing a website that utilizes jQuery File Tree. However, there is an issue with the enormous size of the AJAX response from the server - 900 KB and containing approximately 70,000 'files' (which are not actu ...

Establish a timeout period for ajax requests using jQuery

$.ajax({ url: "test.html", error: function(){ //do something }, success: function(){ //do something } }); At times, the success function performs well, but sometimes it does not. How can I add a timeout to this ajax re ...

Is it possible to stop JSON.stringify from invoking the toJSON method?

JSON.stringify provides a way for objects to customize their serialization process by defining a function named toJSON. Here is an excerpt from the MDN documentation: toJSON() behavior If an object being converted to a string has a method called toJSON, ...

javascript obtain a query string for submission by a form

Suppose you have a form, such as <form id='testform' method="post" action="/" /> <input name="test1" value="yes" type="text"> <input name="test2" value="no" type="text"> </form> Is there a way to retrieve the query s ...

How can the issue of the background fill option covering multiple loading bars be resolved?

I am currently relying on Google Translator, so there may be errors in the translation. The issue I am facing is that when I add a parameter with the "fillColor: '#f4f5f9'", the wheel covers one of the elements of Multiple Bars. I have modified ...

How to Track URL Modifications within an Iframe on an Angular Ionic Mobile Application

Issue I'm currently working on identifying modifications in the URL of an embedded <iframe /> within an Ionic (v5) app using Angular. Solution // ts file @ViewChild('myIframe') public iFrame; backButtonSubscription: Subscription; ...

The Socket.io server is experiencing issues with the "connection" event not firing, and the client event is also not being triggered

I've been struggling to set up an express backend with socket io. No matter what I try, the connection events just won't fire. Both the server and client are using version 3.1.2, so that's not the issue. When I start the client app, I see so ...

navigate to a new page in vue with node.js

As I continue to expand my knowledge in JavaScript, Vue, and Node.js, I encountered a specific issue that I need help with. My goal is to redirect the Vue page after logging in using Node.js. Below you'll find the code snippets for my Vue setup and sc ...

What are the distinctions between manually and programmatically changing URLs in Angular 6?

My query pertains to differentiating navigation methods, specifically between clicking a button with [routerLink] and manually entering a URL in the browser's search bar. Update: I have a fixed menu on a certain page that appears as follows: <ul& ...