simple-tree
v0.1.1
Published
An easy way to create a tree structure in JavaScript
Downloads
3
Readme
SimpleTree
An easy way to create a tree structure in JavaScript
Usage
First, you need to create the tree structure.
var tree = {
root: { value: 'root',
sons:[
{ value: 'A',
sons: [
{ value: 'AA',
sons: [
{ value: 'AA1', sons: [] }
]
},
{ value: 'AAA', sons:[] }
]
},
{ value: 'B',
sons:[
{ value: 'BB', sons: [] }
]
}
]
}
}
Then just create your tree.
Tree.create(tree, function(branch, sons){
//manipule branch and sons
});
The create method receives two parameters: The tree structure and a callback.
Callback
The function passed as the callback takes two parameters: the parent and son. It is used to interact as each element of the tree.
Tree.create(tree, function(obj, son){
console.log(obj.value);
console.log("\t => ", son.value);
});
License
simple-tree is available under the MIT license.