Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. $(function() {
  2.  
  3. $.ajax({
  4. url: 'data.json',
  5. dataType: 'json',
  6. success: function(data) {
  7. /*var arr = $.map(data, function(item){
  8. //item.set = data[item.set];
  9. //console.log(item);
  10. return item;
  11. });
  12.  
  13. for (var i = 0; i<arr.length; i++) {
  14.  
  15. var array = $.map(arr[i].nested, function(child){
  16. return child;
  17. });
  18.  
  19. for(var j = 0;j<array.length;j++){
  20. array[j].text=array[j].label;
  21. delete array[j].label;
  22. }
  23. arr[i].children = array;
  24. arr[i].text = arr[i].label;
  25. delete arr[i].label;
  26. delete arr[i].nested;
  27. }*/
  28. var arr=$.map(data, function(obj){
  29. return{
  30. text:obj.label,
  31. type:obj.type,
  32. description:obj.description,
  33. children:$.map(obj.nested,function(test){
  34. return{
  35. text:test.label,
  36. type:test.type,
  37. description:test.description}
  38. }
  39. )
  40. }})
  41. console.log(arr);
  42.  
  43.  
  44. $('#tree').jstree({
  45. 'core': {
  46. 'data': arr
  47. },
  48. 'types': {
  49. 'file': {
  50. 'icon': 'jstree-file'
  51. },
  52. 'dir': {
  53. 'icon': 'jstree-folder'
  54. }
  55. },
  56. 'plugins': [ 'types' ]
  57. });
  58.  
  59.  
  60.  
  61.  
  62. console.log(arr);
  63. },
  64. statusCode: {
  65. 404: function() {
  66. alert('There was a problem with the server. Try again soon!');
  67. }
  68. }
  69. });
  70.  
  71. // $.ajax({...});
  72.  
  73. alert("Działam - JavaScript :)");
  74.  
  75. // TODO
  76.  
  77. });
  78.  
  79. $("#tree").on("changed.jstree",function(e,data){
  80. //alert("dupa");
  81. $("#description").text(data.node.original.description);
  82. })
  83.  
  84.  
  85.  
  86. /*$(".jstree").click(function(){
  87. alert("dupa");
  88. $("#description").text(event.node.original.description);
  89.  
  90.  
  91.  
  92.  
  93. });*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement