Extjs Tree operations: register events, drag and drop events (target location Judgment), click events, load events, right-click events

Source: Internet
Author: User
  1. VaR tree = ext. tree;
  2. VaR tree = NULL;
  3. Ext. onready (function (){
  4. Tree = new tree. treepanel ({
  5. El: 'tree-Div ',
  6. Onlyleafcheckable: false,
  7. Rootvisible: True,
  8. Autoscroll: True,
  9. Animate: false, // whether to animation
  10. Enabledd: True, // whether drag/drop is supported
  11. Containerscroll: True,
  12. Lines: True,
  13. Checkmodel: 'cascade ',
  14. Loader: new tree. treeloader ({dataurl: '../INFO/RSS. do? Method = getjsonarray ',
  15. Baseattrs: {uiprovider: Ext. Tree. treechecknodeui}
  16. })
  17. });
  18. // Set the root node
  19. VaR root = new tree. asynctreenode (
  20. {
  21. "Text": "My network address ",
  22. "ID": "01 ",
  23. "Allowdrag": false // false indicates that the file cannot be dragged.
  24. }
  25. );
  26. // Events before binding nodes to load
  27. Tree. On ('beforeload', function (node ){
  28. If (node. ID! = '01 '){
  29. Tree. loader. dataurl = '../INFO/RSS. do? Method = getchildjsonarray & nodeid = '+ node. ID;
  30. }
  31. });
  32. // Bind node Click Event
  33. /**//*
  34. Tree. On ('click', function (node ){
  35. If (node. ID! = 'Root '){
  36. Alert (node. ID );
  37. Alert (node. Text );
  38. Alert (node. href );
  39. }
  40. });
  41. */
  42. // Bind the node drag event, find the implementation of Tree node drag for a long time, and finally find this implementation in the post of a foreigner. After dragging, the required information has been captured, you can drag a tree by adding functions linked to the background.
  43. Tree. On ('nodedrop ',
  44. Function (e ){
  45. If (E. Point = 'append '){
  46. Alert ('current "['+ E. dropnode. Text +']" is put under the directory "'Folder e.tar get. Text +! ');
  47. VaR resulturl = "../INFO/RSS. do? Method = treenodetuodong & currenrootid = "+ E. dropnode. ID +" & parentrootid = "paie.tar get. ID +" & type = APPEND ";
  48. VaR resulthtml = xmlhttphelper. Transmit (false, "get", "text", resulturl, null, null );
  49. }
  50. Else if (E. Point = 'ababove '){
  51. // Alert ('current "'+ E. dropnode. Text +'" is placed on "'your e.tar get. Text +! ');
  52. VaR resulturl = "../INFO/RSS. do? Method = treenodetuodong & currenrootid = "+ E. dropnode. ID +" & parentrootid = "paie.tar get. ID +" & type = above ";
  53. VaR resulthtml = xmlhttphelper. Transmit (false, "get", "text", resulturl, null, null );
  54. } Else if (E. Point = 'below '){
  55. // Alert ('current "'+ E. dropnode. Text +'" is placed under "'your e.tar get. Text +! ');
  56. VaR resulturl = "../INFO/RSS. do? Method = treenodetuodong & currenrootid = "+ E. dropnode. ID +" & parentrootid = "paie.tar get. ID +" & type = below ";
  57. VaR resulthtml = xmlhttphelper. Transmit (false, "get", "text", resulturl, null, null );
  58. }
  59. }
  60. );
  61. // Right-click the binding node and choose menu
  62. Tree. On ('textmenu ', function (node, event ){
  63. // Alert ("node. ID =" + node. ID );
  64. Event. preventdefault (); // This line is required
  65. Rightclick. showat (event. getxy (); // obtain the coordinates of the mouse and click to display the menu
  66. // Alert (node. ID );
  67. Document. getelementbyid ('rootid'). value = node. ID;
  68. });
  69. // Right-click the menu
  70. VaR rightclick = new Ext. Menu. menu ({
  71. ID: 'rightclickcont ',
  72. Items :[{
  73. ID: 'rmenu1 ',
  74. Text: 'editor ',
  75. // Add a menu Click Event
  76. Handler: function (node ){
  77. // Alert (node. dropnode. ID );
  78. }
  79. },{
  80. ID: 'rmenu2 ',
  81. Text: 'delete'
  82. },{
  83. ID: 'rmenu3 ',
  84. Text: 'menu 3'
  85. }]
  86. });
  87. Tree. setrootnode (Root );
  88. // Render the tree
  89. Tree. Render ();
  90. Root. Expand ();
  91. });
VaR tree = ext. tree; var tree = NULL; Ext. onready (function () {tree = new tree. treepanel ({El: 'tree-Div ', onlyleafcheckable: false, rootvisible: True, autoscroll: True, animate: false, // whether to animated enabledd: True, // whether to drag and drop containerscroll: True, lines: True, checkmodel: 'cascade ', loader: new tree. treeloader ({dataurl :'.. /INFO/RSS. do? Method = getjsonarray ', baseattrs: {uiprovider: ext. tree. treechecknodeui}); // set the root node var root = new tree. asynctreenode ({"text": "", "ID": "01", "allowdrag": false // false indicates that the object cannot be dragged }); // bind the node to load the previous event tree. on ('beforeload', function (node) {If (node. ID! = '01') {tree. loader. dataurl = '../INFO/RSS. do? Method = getchildjsonarray & nodeid = '+ node. id ;}}); // click event/** // * tree for binding nodes. on ('click', function (node) {If (node. ID! = 'Root') {alert (node. ID); alert (node. text); alert (node. href) ;}}); * // bind a node drag event, find the implementation of Tree node drag for a long time, and finally find this implementation in the post of a foreigner, after dragging, the required information has been captured. You can drag the tree by adding the function associated with the background. on ('nodedrop', function (e) {If (E. point = 'append') {alert ('current "['+ E. dropnode. text + '] "put to the directory" folder 'Folder e.tar get. text +! '); Var resulturl = "../INFO/RSS. do? Method = treenodetuodong & currenrootid = "+ E. dropnode. ID + "& parentrootid =" paie.tar get. ID + "& type = APPEND"; var resulthtml = xmlhttphelper. transmit (false, "get", "text", resulturl, null, null);} else if (E. point = 'ababove ') {// alert ('current "' + E. dropnode. text + '"is placed in" 'your e.tar get. text + '"above! '); Var resulturl = "../INFO/RSS. do? Method = treenodetuodong & currenrootid = "+ E. dropnode. ID + "& parentrootid =" paie.tar get. ID + "& type = above"; var resulthtml = xmlhttphelper. transmit (false, "get", "text", resulturl, null, null);} else if (E. point = 'below') {// alert ('current "'+ E. dropnode. text + '"is placed in" 'your e.tar get. text +! '); Var resulturl = "../INFO/RSS. do? Method = treenodetuodong & currenrootid = "+ E. dropnode. ID + "& parentrootid =" paie.tar get. ID + "& type = below"; var resulthtml = xmlhttphelper. transmit (false, "get", "text", resulturl, null, null) ;}}); // right-click the binding node and choose the function tree. on ('textmenu ', function (node, event) {// alert ("node. id = "+ node. ID); event. preventdefault (); // This line is required. showat (event. getxy (); // get the coordinates of the mouse and click to display the menu // alert (node. ID); document. getelementbyid ('rootid '). value = node. ID;}); // right-click the menu var rightclick = new Ext. menu. menu ({ID: 'rightclickcont', items: [{ID: 'rmenu1', text: 'edit', // Add a menu Click Event Handler: function (node) {// alert (node. dropnode. ID) ;}},{ ID: 'rmenu2 ', text: 'delete' },{ ID: 'rmenu3', text: 'menu 3'}]}); tree. setrootnode (Root); // render the tree. render (); root. expand ();});

Original post address: http://www.cnblogs.com/huazi4995/articles/1245150.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.