Guest User

Untitled

a guest
Jan 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. var $tree = $('.jstree', myContext),
  2. node = $tree.find('li').filter(function() {
  3. return ( $(this).data().location || {}).id === 158;
  4. });
  5. $tree.jstree('select_node', n)
  6.  
  7. .on('loaded.jstree', function() {
  8. // Do something here...
  9. });
  10.  
  11. jQuery("#getStartedTree").jstree("select_node", "#test2");
  12.  
  13. The JSON in the TextFile.txt - borrowed from your simple example
  14. [
  15. {
  16. "data" : "A node",
  17. "children" : [ "Child 1", "Child 2" ]
  18. },
  19. {
  20. "attr" : { "id" : "test1" },
  21. "data" : {
  22. "title" : "Long format demo",
  23. "attr" : { "id" : "test2", "href" : "#" }
  24. }
  25. }
  26. ]
  27.  
  28. My tree container is <div id="getStartedTree">
  29.  
  30. My jsTree code
  31. $("#getStartedTree").jstree({
  32. "themes": {
  33. "theme": "default",
  34. "url": "../App_Css/Themes/Default/style.css",
  35. "dots": true,
  36. "icons": true
  37. },
  38. "json_data": {
  39. "ajax": {
  40. "url": "../SiteMaps/TextFile.txt",
  41. "dataType": "json",
  42. "data": function(n) {
  43. return { id: n.attr ? n.attr("id") : 0 };
  44. }
  45. }
  46. },
  47. "plugins": ["themes", "json_data", "ui"]
  48. });
  49.  
  50. $(treeIdHandle + " li[id=" + nodeId + "] a").click();
  51.  
  52. // after the tree is loaded
  53. $(".jstree").on("loaded.jstree", function(){
  54. // don't use "#" for ID
  55. $('.jstree').jstree(true).select_node('ElementId');
  56. });
  57.  
  58. // after the tree is loaded
  59. $(".jstree").on("loaded.jstree", function(){
  60. // don't use "#" for ID
  61. $('.jstree').jstree(true).select_node('ElementId');
  62. });
  63.  
  64. // after the tree is loaded
  65. $(".jstree").on("loaded.jstree", function(){
  66. // don't use "#" for ID
  67. $('.jstree').jstree(true).select_node('ElementId');
  68. });
  69.  
  70. $(".jstree").on("loaded.jstree", function(){
  71. <?php foreach($tree as $node): ?>
  72. $('.jstree').jstree(true).select_node('<?=$node?>');
  73. <?php endforeach;?>
  74. });
  75.  
  76. $('.jstree').jstree(true).select_node('element id');
  77.  
  78. jQuery.each(produto.categorias, function(i, categoria) {
  79. $('#lista-categorias').jstree(true).select_node(categoria.dadoCategoria.id);
  80. });
  81.  
  82. <div class="tree-menu">
  83. <ul class="menu">
  84. <li id="node_1">
  85. Node 1 - Level 1
  86. <ul class="menu">
  87. <li id="node_3">
  88. Node 3 - Level 2
  89. </li>
  90. </ul>
  91. </li>
  92. <li id="node_2">
  93. Node 2 - Level 1
  94. </li>
  95. </ul>
  96. </div>
  97.  
  98. $('.tree-menu').jstree(true).select_node("node_3");
Add Comment
Please, Sign In to add comment