Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

270
Views
how to use variable in jstree data?

this is my code

var treedata = ['{ "id" : "ajson1", "parent" : "#", "text" : "Customer" }', 
   '{ "id" : "ajson2", "parent" : "ajson1", "text" : "Order number" }',
   '{ "id" : "ajson3", "parent" : "ajson1", "text" : "Date" }',      
   '{ "id" : "ajson4", "parent" : "#", "text" : "Company Name" }',
   '{ "id" : "ajson5", "parent" : "#", "text" : "Contact Name" }',
   '{ "id" : "ajson6", "parent" : "#", "text" : "Name1" }',
   '{ "id" : "ajson7", "parent" : "#", "text" : "Product number1" }'];

$('#data').jstree({
        'core' : {
            'data' : treedata 
        }
    });

but when i run it it do nothing but we i use this



$('#data').jstree({
        'core' : {
            'data' : {
                   ['{ "id" : "ajson1", "parent" : "#", "text" : "Customer" }', 
   '{ "id" : "ajson2", "parent" : "ajson1", "text" : "Order number" }',
   '{ "id" : "ajson3", "parent" : "ajson1", "text" : "Date" }',      
   '{ "id" : "ajson4", "parent" : "#", "text" : "Company Name" }',
   '{ "id" : "ajson5", "parent" : "#", "text" : "Contact Name" }',
   '{ "id" : "ajson6", "parent" : "#", "text" : "Name1" }',
   '{ "id" : "ajson7", "parent" : "#", "text" : "Product number1" }'];

}
        }
    });

it work so how can i use variable in data ??

i wanted to run first code but it is not working

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Do you mean that you want to use a variable for a property value?

If you just want to use the variable:

let n = 42;

const obj = {
  'id': n
}

If you want to place the variable within a string, any of the following works:

let name = 'Bob';

const obj = {
  'description1': `User, ${name}, is cool`,
  'description2': 'User, ' + name + ', is cool',
  'description3': 'User, '.concat(name, ', is cool')
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!