"Jstree" generates jsTree-001

Source: Internet
Author: User

<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

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.