UNPKG

tree-model

Version:

Manipulate and traverse tree-like structures in javascript.

30 lines (25 loc) 695 B
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <script src="jquery.js"></script> <script src="tree-model.js"></script> <script> $(function() { var tree = new TreeModel(); var root = tree.parse({name: 'a', text: 'node a', children: [{name: 'b', text: 'node b'}]}); // direct children of root node as nodes var children = root.children; var childB = children[0]; // This will print 'node b' $('body').append('<p>' + childB.model.text + '</p>') // This will print 'node a' $('body').append('<p>' + childB.parent.model.text + '</p>') }); </script> <title>tree-model</title> </head> <body> </body> </html>