example-dom.html 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Bootstrap Tree View</title>
  5. <link href="./bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
  6. <link href="./css/bootstrap-treeview.css" rel="stylesheet">
  7. </head>
  8. <body>
  9. <div class="container">
  10. <h1>Bootstrap Tree View - DOM Tree</h1>
  11. <br/>
  12. <div class="row">
  13. <div class="col-sm-12">
  14. <label for="treeview"></label>
  15. <div id="treeview"/>
  16. </div>
  17. </div>
  18. </div>
  19. <script src="./bower_components/jquery/dist/jquery.js"></script>
  20. <script src="./js/bootstrap-treeview.js"></script>
  21. <script type="text/javascript">
  22. function buildDomTree() {
  23. var data = [];
  24. function walk(nodes, data) {
  25. if (!nodes) { return; }
  26. $.each(nodes, function (id, node) {
  27. var obj = {
  28. id: id,
  29. text: node.nodeName + " - " + (node.innerText ? node.innerText : ''),
  30. tags: [node.childElementCount > 0 ? node.childElementCount + ' child elements' : '']
  31. };
  32. if (node.childElementCount > 0) {
  33. obj.nodes = [];
  34. walk(node.children, obj.nodes);
  35. }
  36. data.push(obj);
  37. });
  38. }
  39. walk($('html')[0].children, data);
  40. return data;
  41. }
  42. $(function() {
  43. var options = {
  44. bootstrap2: false,
  45. showTags: true,
  46. levels: 5,
  47. data: buildDomTree()
  48. };
  49. $('#treeview').treeview(options);
  50. });
  51. </script>
  52. </body>