Multi-functional jquery Tree plugin Ztree A simple example of implementing a permission list _jquery

Source: Internet
Author: User

Ztree is a multifunctional "tree plug-in" that relies on jquery implementations. Excellent performance, flexible configuration, a combination of multiple functions is the biggest advantage of Ztree.

Ztree official website
Ztreeapi Download Link

The page mainly introduces several files:

<link type= "Text/css" rel= "stylesheet" href= "Ztree/ztreestyle.css"/> <script "type="
Src= "Js/jquery.ztree.core-3.5.js" ></script>
<script type= "Text/javascript" src= "js/" Jquery.ztree.excheck-3.5.js "></script> 

HTML page:

 <div class= "Edit_content" >
      <div class= "qxlb" >
        <div class= "Add_title" > 
          <span> Permissions List </span>
        </div>
        <div class= "qxlb_content" >
        <ul id= "tree" class= "Ztree" > </ul>
        </div>
      </div>
 </div>

Core JS:

 <script type= "Text/javascript" > var ztree; Create tree structure function Createtree () {var setting = {check:{Enable:true}, view: {dblclickexpand: True, Expandspeed: ""},/////Asynchronous Loading async: {enable:true,//setting whether URL is loaded asynchronously: "<%=path%>/role/g Etresourceslist.do ",//Set the URL address of the asynchronous fetch node Otherparam: [" Roleid ", ' ${updaterole.id} ']},//This data
        Face of the pidkey,idkey,name and so on and so on are the corresponding background detection field name, in the SQL write well or in the concatenation of JSON when the first stitching good, before too much time as long as the corresponding can be data: {simpledata: {
          Enable:true, Pidkey: "ParentID", Idkey: "ID"}, Key: {checked: "Checked",
  Name: ' Name '}}, callback: {onasyncsuccess:ztreeonasyncsuccess}};  
  Initialize Ztree = $.fn.ztree.init ($ ("#tree"), setting);
Ztree.expandall (TRUE);
/* Asynchronous load cannot expand tree default expand Level menu */var firstasyncsuccessflag = 0; 
 function Ztreeonasyncsuccess (event, Treeid, msg) {if (Firstasyncsuccessflag = 0) {    try {//Call defaults to expand the first node var selectednode = Ztree.getselectednodes (); 
         var nodes = Ztree.getnodes (); 
         Ztree.expandnode (Nodes[0], true); 
         var childnodes = Ztree.transformtoarray (Nodes[0]); 
         Ztree.expandnode (Childnodes[1], true); 
         Ztree.selectnode (Childnodes[1]); 
         var childNodes1 = Ztree.transformtoarray (childnodes[1]); 
         Ztree.checknode (Childnodes1[1], true, true); 
      Firstasyncsuccessflag = 1;  
The catch (Err) {}}} $ (function () {//Page load complete create tree createtree ();

});
  function Submitrole () {//Get selected node, upload to background var nodes = Ztree.getcheckednodes ();
  var ids = [];
  for (Var i=0,l=nodes.length;i<l;i++) {Ids[ids.length] = nodes[i].id;
  }//var _resourcesids=ids.join (",");
      
  document.getElementById ("Hidden_resourcelist"). Value=ids.join (",");
$ ("#resourcesRoleListForm"). Submit ();
 } </SCRIPT>

The data is realized through the backstage recursive query, which is passed to the foreground and receives in the form of JSON. More content can refer to the API, the example inside is very detailed.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.