I´m striving to get some aggregated data from Mongo DB. I have the following collections:
I´m striving to get some aggregated data from Mongo DB. I have the following collections:
I have 2 collections:
product
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c5"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feec",
"5eb92a7909823240081cd763"
],
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X10",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
},
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c8"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feed",
"5eb92a7909823240081cd763"
],
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X11",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
}
2. attribute
{
"_id" : ObjectId("5eb92a4d09823240081cd75f"),
"is_active" : true,
"name" : "Color",
"slug" : [
{
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd763"),
"name" : "Green",
"updatedAt" : ISODate("2020-06-01T13:47:56.584Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
},
{
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd764"),
"name" : "RED",
"updatedAt" : ISODate("2020-06-01T13:47:39.236Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
}
],
"createdAt" : ISODate("2020-05-11T10:34:53.642Z"),
"updatedAt" : ISODate("2020-06-01T13:48:09.194Z"),
"__v" : 0
},
{
"_id" : ObjectId("5eb92a5409823240081cd760"),
"is_active" : true,
"name" : "Size",
"slug" : [
{
"is_active" : true,
"_id" : ObjectId("5eb92c4338d0b83a3088feeb"),
"name" : "M",
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"createdAt" : ISODate("2020-05-11T10:43:15.355Z")
},
{
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feec"),
"name" : "S",
"updatedAt" : ISODate("2020-05-11T10:59:16.731Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
},
{
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feed"),
"name" : "XXL",
"updatedAt" : ISODate("2020-06-01T13:46:36.417Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
}
],
"createdAt" : ISODate("2020-05-11T10:35:00.739Z"),
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"__v" : 0
}
I want to this type of result
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c5"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feec",
"5eb92a7909823240081cd763"
],
"attributes" : [
{
"_id" : ObjectId("5eb92a5409823240081cd760"),
"is_active" : true,
"name" : "Size",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feec"),
"name" : "S",
"updatedAt" : ISODate("2020-05-11T10:59:16.731Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
},
"createdAt" : ISODate("2020-05-11T10:35:00.739Z"),
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"__v" : 0
},
{
"_id" : ObjectId("5eb92a4d09823240081cd75f"),
"is_active" : true,
"name" : "Color",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd763"),
"name" : "Green",
"updatedAt" : ISODate("2020-06-01T13:47:56.584Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
},
"createdAt" : ISODate("2020-05-11T10:34:53.642Z"),
"updatedAt" : ISODate("2020-06-01T13:48:09.194Z"),
"__v" : 0
}
]
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X10",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
},
{
"_id" : ObjectId("5eda578cb9c3fa1ef8c483c8"),
"brand_name" : "LAVA",
"short_description" : "Specifications",
"offer_price" : 20,
"quantity" : 5,
"variants" : [
"5eb9300438d0b83a3088feed",
"5eb92a7909823240081cd763"
],
"attributes" : [
{
"_id" : ObjectId("5eb92a5409823240081cd760"),
"is_active" : true,
"name" : "Size",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb9300438d0b83a3088feed"),
"name" : "XXL",
"updatedAt" : ISODate("2020-06-01T13:46:36.417Z"),
"createdAt" : ISODate("2020-05-11T10:59:16.731Z")
},
"createdAt" : ISODate("2020-05-11T10:35:00.739Z"),
"updatedAt" : ISODate("2020-06-01T13:47:08.993Z"),
"__v" : 0
},
{
"_id" : ObjectId("5eb92a4d09823240081cd75f"),
"is_active" : true,
"name" : "Color",
"slug" : {
"is_active" : true,
"_id" : ObjectId("5eb92a7909823240081cd763"),
"name" : "Green",
"updatedAt" : ISODate("2020-06-01T13:47:56.584Z"),
"createdAt" : ISODate("2020-05-11T10:35:37.357Z")
},
"createdAt" : ISODate("2020-05-11T10:34:53.642Z"),
"updatedAt" : ISODate("2020-06-01T13:48:09.194Z"),
"__v" : 0
}
]
"seller_id" : ObjectId("5e994af17a2f9b3a007e247c"),
"name" : "LAVA X11",
"createdAt" : ISODate("2020-06-05T14:32:44.582Z"),
"updatedAt" : ISODate("2020-06-05T14:32:44.582Z")
}
// ------------ Here variants array values are attribute's slug ID -----------------
Please Help Me
Please let me know how?
That's not very effective data design: one of your collections uses ids of parts of documents in other collection. First of all you need to consider having slug._id: 1 index for attributes. Then to fetch products with included attributes which have filtered slugs use something like
db.product.find(...).map(function(prod){
prod.attributes = [];
for(sid in prod.variants){
var attr = db.attributes.find({'slug._id': sid});
attr.slug = attr.slug.find(function(slug){return slug._id == sid});
prod.atributes.push(attr);
}
return prod;
})
Related
I have a user document as follows which holds an array of systemIDs', which is unique for another collection which holds systemID as unikey key. How to populate user with all system ID details?
User document:
{
"_id" : ObjectId("6gfg85993266db5fdgs578"),
"email" : "xyz#gmail.com",
"role" : "user",
"systemIDs" : [
"12345678",
"87654321"
],
"createdAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"updatedAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("6gfg85993266db5fdgs578"),
"email" : "abc#gmail.com",
"role" : "user",
"systemIDs" : [
"1111111",
"2135684"
],
"createdAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"updatedAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"__v" : NumberInt(0)
}
System IDs document:
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "12345678",
"err" : [
1, 5, 10
],
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "87654321",
"err" : [
3, 7
],
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("62087dsfsdfs97e1"),
"systemID" : "11111111",
"err" : [
],
"__v" : NumberInt(0)
},
I want to find details of all the systemIDs a user holds which results something like this if I query my users collection with email : xyz#gmail.com, I should get the below result or populated result like shown:
{
"_id" : ObjectId("6gfg85993266db5fdgs578"),
"email" : "xyz#gmail.com",
"role" : "user",
"systemIDs" : [
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "12345678",
"err" : [
1, 5, 10
],
"__v" : NumberInt(0)
},
{
"_id" : ObjectId("62093fdsfsdfs97e1"),
"systemID" : "87654321",
"err" : [
3, 7
],
"__v" : NumberInt(0)
},
]
"createdAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"updatedAt" : ISODate("2022-02-13T16:31:34.119+0000"),
"__v" : NumberInt(0)
},
I can create a foreach loop and call database each time but I suppose that wouldn't be a good practice.
I am new with this so please bear with me and explain it to me in details.
you can use aggregation with $match and $lookup to perform this task
db.users.aggregate([
{
"$match": {
"email": "xyz#gmail.com"
}
},
{
"$lookup": {
"from": "systems",
"localField": "systemIDs",
"foreignField": "systemID",
"as": "systemIDs"
}
}
])
demo
I have an array of Objects and I want to filter and ftech only part of object which I will be sending as a body parameter to an API.
Below is my code,however it returns me an array and inside that I have my object.I don't want it to be an array but just an Object.
How can I achieve this.
Original Array of Objects:
[ {
"flowId" : 11,
"flowName" : "jobtest003",
"version" : 1,
"ingestionFlowId" : "",
"jobCreatedDate" : "25-05-2020",
"jobUpdateDate" : "28-06-2020",
"jobLastRunDate" : "29-06-2020",
"active" : false,
"properties" : [ {
"id" : 12,
"key" : "sourceTable",
"value" : "job002",
"category" : "General Settings"
}, {
"id" : 13,
"key" : "Source",
"value" : "api",
"category" : "Source Properties"
}, {
"id" : 147,
"key" : "Target Path",
"value" : "/raw/au/jackson",
"category" : "Destination Properties"
} ]
}, {
"flowId" : 21,
"flowName" : "jobtest004",
"version" : 1,
"ingestionFlowId" : null,
"jobCreatedDate" : "25-05-2020",
"jobUpdateDate" : "28-06-2020",
"jobLastRunDate" : "29-06-2020",
"active" : false,
"properties" : [ {
"id" : 21,
"key" : "sourceTable",
"value" : "job003",
"category" : "General Settings"
}, {
"id" : 22,
"key" : "Source",
"value" : "api",
"category" : "Source Properties"
}, {
"id" : 23,
"key" : "Client ID",
"value" : "ebf73456-443e-4986-941b-057906d25e2f",
"category" : "Destination Properties"
}, {
"id" : 147,
"key" : "Target Path",
"value" : "/raw/au/jackson",
"category" : "Destination Properties"
} ]
}, {
"flowId" : 22,
"flowName" : "jobtest004",
"version" : 1,
"ingestionFlowId" : null,
"jobCreatedDate" : "25-05-2020",
"jobUpdateDate" : "28-06-2020",
"jobLastRunDate" : "29-06-2020",
"active" : false,
"properties" : [ {
"id" : 21,
"key" : "sourceTable",
"value" : "job003",
"category" : "General Settings"
}, {
"id" : 22,
"key" : "Source",
"value" : "api",
"category" : "Source Properties"
}, {
"id" : 23,
"key" : "Client ID",
"value" : "ebf73456-443e-4986-941b-057906d25e2f",
"category" : "Destination Properties"
}, {
"id" : 147,
"key" : "Target Path",
"value" : "/raw/au/jackson",
"category" : "Destination Properties"
} ]
} ]
The result I want :
{
"flowId" : 20,
"flowName" : "jobtest004",
"version" : 1,
"ingestionFlowId" : null,
"jobCreatedDate" : "25-05-2020",
"jobUpdateDate" : "28-06-2020",
"jobLastRunDate" : "29-06-2020",
"active" : false,
"properties" : [ {
"id" : 21,
"key" : "sourceTable",
"value" : "job003",
"category" : "General Settings"
}, {
"id" : 22,
"key" : "Source",
"value" : "api",
"category" : "Source Properties"
}, {
"id" : 23,
"key" : "Client ID",
"value" : "ebf73456-443e-4986-941b-057906d25e2f",
"category" : "Destination Properties"
}, {
"id" : 147,
"key" : "Target Path",
"value" : "/raw/au/jackson",
"category" : "Destination Properties"
} ]
}
The result I am getting:
[{
"flowId" : 20,
"flowName" : "jobtest004",
"version" : 1,
"ingestionFlowId" : null,
"jobCreatedDate" : "25-05-2020",
"jobUpdateDate" : "28-06-2020",
"jobLastRunDate" : "29-06-2020",
"active" : false,
"properties" : [ {
"id" : 21,
"key" : "sourceTable",
"value" : "job003",
"category" : "General Settings"
}, {
"id" : 22,
"key" : "Source",
"value" : "api",
"category" : "Source Properties"
}, {
"id" : 23,
"key" : "Client ID",
"value" : "ebf73456-443e-4986-941b-057906d25e2f",
"category" : "Destination Properties"
}, {
"id" : 147,
"key" : "Target Path",
"value" : "/raw/au/jackson",
"category" : "Destination Properties"
} ]
}]
I don't want my result to be an array instead I just want it to be an Object.
Use find method of array as follows.
var array = your data;
var object_needed = array.find(d=>d.flowId == 21)//use required id in place of 21 or use required property in place of .flowIf
//console.log(object_needed)
Hope this helps!!!
For that you can use find method on the Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
With your explanation if I have understood right
Array.prototype.filter will always return an array only, you have to use array index to get the object out of array
Use reduce method to convert array into object.
const convertArrayToObject = (array, key) => {
const initialValue = {};
return array.reduce((obj, item) => {
return {
...obj,
[item[key]]: item,
};
}, initialValue);
};
let testData = [ { "flowId" : 11, "flowName" : "jobtest003", "version" : 1, "ingestionFlowId" : "", "jobCreatedDate" : "25-05-2020", "jobUpdateDate" : "28-06-2020", "jobLastRunDate" : "29-06-2020", "active" : false, "properties" : [ { "id" : 12, "key" : "sourceTable", "value" : "job002", "category" : "General Settings" }, { "id" : 13, "key" : "Source", "value" : "api", "category" : "Source Properties" }, { "id" : 147, "key" : "Target Path", "value" : "/raw/au/jackson", "category" : "Destination Properties" } ] }, { "flowId" : 21, "flowName" : "jobtest004", "version" : 1, "ingestionFlowId" : null, "jobCreatedDate" : "25-05-2020", "jobUpdateDate" : "28-06-2020", "jobLastRunDate" : "29-06-2020", "active" : false, "properties" : [ { "id" : 21, "key" : "sourceTable", "value" : "job003", "category" : "General Settings" }, { "id" : 22, "key" : "Source", "value" : "api", "category" : "Source Properties" }, { "id" : 23, "key" : "Client ID", "value" : "ebf73456-443e-4986-941b-057906d25e2f", "category" : "Destination Properties" }, { "id" : 147, "key" : "Target Path", "value" : "/raw/au/jackson", "category" : "Destination Properties" } ] }, { "flowId" : 22, "flowName" : "jobtest004", "version" : 1, "ingestionFlowId" : null, "jobCreatedDate" : "25-05-2020", "jobUpdateDate" : "28-06-2020", "jobLastRunDate" : "29-06-2020", "active" : false, "properties" : [ { "id" : 21, "key" : "sourceTable", "value" : "job003", "category" : "General Settings" }, { "id" : 22, "key" : "Source", "value" : "api", "category" : "Source Properties" }, { "id" : 23, "key" : "Client ID", "value" : "ebf73456-443e-4986-941b-057906d25e2f", "category" : "Destination Properties" }, { "id" : 147, "key" : "Target Path", "value" : "/raw/au/jackson", "category" : "Destination Properties" } ] } ];
console.log(
convertArrayToObject(testData,'flowId')
);
click here for detailed explanation
You can use find method as below which will return only object
arrayOfData.find(function(obj){
return obj.Id == 11
})
or
arrayOfData.find(obj => obj.Id == 11)
I have a firebase database with the following structure of employee data. I have a user table as well which has a 'companyId' property. Each time a user logs in I want to fetch all the employees which match the users 'companyId'. Is it possible to implement this using firebase database rules or I have to write some query.
Employee:
{
"+911234567890" : {
"admin" : true,
"companyId" : "C1",
"depId" : "D5",
"designation" : "D1",
"dob" : "2019-04-02T18:30:00.000Z",
"doj" : "2019-04-18T18:30:00.000Z",
"empEmail" : "nishant.k#zetwerk.com",
"empId" : "E4",
"empPhone" : "+911234567890",
"first_name" : "Nishanth",
"gender" : "male",
"last_name" : "K",
"manager" : "M2",
"type" : "permanent"
},
"+919035105184" : {
"admin" : true,
"companyId" : "C2",
"depId" : "D1",
"designation" : "Software engineer",
"dob" : "1991-07-31T18:30:00.000Z",
"doj" : "2018-07-24T18:30:00.000Z",
"empEmail" : "arpit.s#zetwerk.com",
"empId" : "E10",
"empPhone" : "+919035105184",
"first_name" : "Arpit",
"gender" : "male",
"last_name" : "Srivastava",
"manager" : "M1",
"type" : "PERMANANENT"
},
"+919698286236" : {
"admin" : false,
"companyId" : "C1",
"companyName" : "Zetwerk",
"depId" : "D1",
"depName" : "Engineering",
"empEmail" : "dhanalakshmi.s#zetwerk.com",
"empId" : "E1",
"empPhone" : "+919698286236",
"firebaseId" : "-LbNvaKFjqaaMl_JbNxd",
"first_name" : "Dhanalakshmi",
"type" : "contract"
},
"+919738749877" : {
"companyId" : "C1",
"depId" : "D2",
"empEmail" : "sagar.k#zetwerk.com",
"empId" : "E3",
"empPhone" : "+919738749877",
"firebaseId" : "-LbNbABScOEzl-sMFE1u",
"first_name" : "Sagar",
"type" : "permanent"
},
"+919972984851" : {
"admin" : true,
"companyId" : "C1",
"depId" : "D6",
"designation" : "SDE",
"dob" : "2019-04-23T18:30:00.000Z",
"doj" : "2019-04-02T18:30:00.000Z",
"empEmail" : "saikumarganji1994#gmail.com",
"empId" : "Z002",
"empPhone" : "+919972984851",
"first_name" : "Sai",
"gender" : "male",
"last_name" : "Kumar",
"type" : "permanent"
}
}
User:
"1":{
"Name" : "Nishant Gupta",
"companyId" : "C1",
"role" : "admin"
}
You indeed have to use a query, as follows. I make the assumption that you know, in your front end, the user's companyId;
var db = firebase.database();
var userCompanyId = 'C1'; //you'll probably get this value from the user profile
db.ref('Employee')
.orderByChild('companyId')
.equalTo(userCompanyId)
.once('value', function(dataSnapshot) {
dataSnapshot.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
console.log('childKey : ', childKey);
console.log('childData : ', childData);
});
});
See the doc here: https://firebase.google.com/docs/database/web/lists-of-data#listen_for_value_events
I have the following firebase database. I would like to filter and list the orders which's deliveryDuration value is "45"
"orders" : [ null, {
"comment" : "",
"date" : "2018-07-09 10:07:18",
"deliveryDuration" : "45",
"delivery_address" : "",
"item" : [ {
"available" : true,
"category" : "Dessert",
"details" : "(Hausgemacht)",
"name" : "Warmer Topfenstrudel",
"price" : 3.9,
"quantity" : 1
} ],
"orderVerified" : false,
"telefon" : "",
"userID" : "xyc#gmail.com",
"userName" : ""
}, {
"comment" : "",
"date" : "2018-07-10 10:07:33",
"deliveryDuration" : "30",
"delivery_address" : "",
"item" : [ {
"available" : true,
"category" : "Dessert",
"details" : "(Hausgemacht)",
"name" : "Warmer Topfenstrudel",
"price" : 3.9,
"quantity" : 1
} ],
"orderVerified" : false,
"telefon" : "",
"userID" : "xyc#gmail.com",
"userName" : ""
}, {
"comment" : "",
"date" : "2018-07-10 10:13:13",
"deliveryDuration" : "10",
"delivery_address" : "",
"item" : [ {
"available" : true,
"category" : "Spezialitäten",
"details" : "Schweinschnitzel mit Parmesan gebacken auf Spaghetti Napoli",
"name" : "Piccata Milanese",
"price" : 12.9,
"quantity" : 1
} ],
"orderVerified" : false,
"telefon" : "",
"userID" : "xyc#gmail.com",
"userName" : ""
}
}
I tried writing the following function:
getNewItems: function (order) {
if (db.ref('orders').child(order).child('deliveryDuration').equalTo(45)){
return db.ref('orders').child(order).child('deliveryDuration')
}}
How could I get the filtered objects? I was thinking that that i write an if-else statement and the function returns the values what i was looking for.
I think you're looking for this:
getNewItems: function (order) {
return db.ref('orders').orderByChild('deliveryDuration').equalTo(45));
}}
This Firebase query takes each child node of the location you query, orders it by the deliveryDuration property, and then filters to only get the ones who are equal to 45.
I am working on creating tree panel in Extjs version 3.2.1 , i have code to construct a tree from xml document(tree.xml) which is available in my server which is working fine .
But i am in new situation,Where my response is saved in global constant variable
From Ext.Ajax request i got response and saved like following
global_const = response.responseXML;
My Question is , How i can pass this global_const into treeloader?
Any help and suggestion is thankful
I used json instead xml
var Tree = Ext.tree;
var tree = new Tree.TreePanel('tree', {
animate:true,
enableDD:false,
loader: new Tree.TreeLoader(), // Note: no dataurl, register a TreeLoader to make use of createNode()
lines: true,
selModel: new Ext.tree.MultiSelectionModel(),
containerScroll: false
});
// json data describing the tree
var json =
[
{"text" : "Audi", "id" : 100, "leaf" : false, "cls" : "folder", "children" : [
{"text" : "A3", "id" : 1000, "leaf" : false, "cls" : "folder", "children" :
[ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"},
{"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"},
{"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"},
{"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"},
{"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"}
]
},
{"text" : "TT", "id" : 1000, "leaf" : false, "cls" : "folder", "children" :
[ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"},
{"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"},
{"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"},
{"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"},
{"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"}
]
}]
},
{"text" : "Cadillac", "id" : 300, "leaf" : false, "cls" : "folder", "children" : [
{"text" : "CTS", "id" : 1000, "leaf" : false, "cls" : "folder", "children" :
[ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"},
{"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"},
{"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"},
{"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"},
{"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"}
]
},
{"text" : "CTS-V", "id" : 1000, "leaf" : false, "cls" : "folder", "children" :
[ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"},
{"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"},
{"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"},
{"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"},
{"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"}
]
}]
}
];
// set the root node
var root = new Tree.AsyncTreeNode({
text: 'Autos',
draggable:false,
id:'source',
children: json
});
tree.setRootNode(root);
tree.render();
root.expand();