<span style= "FONT-SIZE:14PX;" ><script>varr = [];//leaf nodes selected in the permission tree varCurrentgroupid; functionShowpermittree (ID) {Currentgroupid=ID; $.ajax ({data:"Currentgroupid=" +ID, type:"POST", //dataType: ' JSON ',URL: "/test/permittree", Error:function(data) {alert ("Something went wrong!!" :" +data); }, Success:function(data) {//alert ("Success:" + data);createpermittree (data); } }); ${' Buttondiv '}.style.display= ""; } functionCreatepermittree (datastr) {datastr= Eval ("" + Datastr + ""); $(' #permitTree '). Jstree ({' Plugins ': ["Wholerow", "checkbox", "Types" ], ' Core ' : { "Themes" : { "Responsive":false }, ' Data ': Datastr},"Types" : { "Default" : { "icon": "FA fa-folder icon-state-warning icon-lg" }, "File" : { "icon": "FA fa-file icon-state-warning icon-lg" } } }); } //Listen for event$ (' #permitTree '). On (' Changed.jstree ',function(E, data) {R= []; varI, J; for(i = 0, j = data.selected.length; I < J; i++) { varnode =Data.instance.get_node (Data.selected[i]); if(Data.instance.is_leaf (node)) {R.push (node.id); } } //alert (' Selected: ' + r.join (' @@ ')); }) functionSavetree () {$.ajax ({data: {' Currentgroupid ': Currentgroupid,' Selectednodes ': R.join (' @@ '))}, type:"POST", //dataType: ' JSON ',URL: "/test/savetree", Error:function(data) {alert ("Something went wrong!!" :" +data); }, Success:function(data) {alert ("Saved successfully!"); } }); } </script></span><span style= "FONT-SIZE:24PX;" ></span>
View Code
1. Ajax Request Generation Jstree
2. Jstree Change Event
The above code contains a change event. Put the ID of all the selected nodes into an array.
There is a button on the page, click to trigger the Savetree function, send a request to the background, the ID of the selected node is sent to the background.
<script>$(' #jstree '). Jstree ({core: {check_callback:true, data: [{"id": "1", "Parent": "#", "text": "Root" }, { "id": "2", "Parent": "1", "text": "Child 1" }, { "id": "3", "Parent": "1", "text": "Child 2"}],}, plugins: ["Wholerow", "ContextMenu"], "ContextMenu": { "Items": { "Create":NULL, "Rename":NULL, "Remove":NULL, "CCP":NULL, "Add": { "Label": "Add", "Action":function(obj) {varInst =jQuery.jstree.reference (obj.reference); varClickednode =Inst.get_node (obj.reference); Alert ("Add Operation--clickednode ' s ID is:" +clickednode.id); } }, "Delete": { "Label": "Delete", "Action":function(obj) {varInst =jQuery.jstree.reference (obj.reference); varClickednode =Inst.get_node (obj.reference); Alert ("Delete Operation--clickednode ' s ID is:" +clickednode.id); }}}). On ("Ready.jstree",function(E, data) {Data.instance.open_all ();});</script>
View Code
Reprinted from http://blog.csdn.net/hejinwei_1987/article/details/46822671
"Jstree" generates jsTree-001