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
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')
};