JQuery sample code for writing a dynamic tree _ jquery-js tutorial

Source: Internet
Author: User
This article describes how to use JQuery to write a dynamic tree. The Code is as follows:


// Business type tree
Var settingOther = {
Edit :{
Enable: false
},
// Asynchronously load the tree
Async :{
Enable: true,
Url: "initCoagencyTree. action ",
AutoParam: ["id", "name = n"],
OtherParam: {"otherParam": "zTreeAsyncTest "},
DataFilter: filter
},
// Simple data format
Data :{
SimpleData :{
Enable: true
}
},
// Callback function
Callback :{
BeforeClick: beforeClick,
OnClick: onClick
}
};
// Mouse event
Function beforeClick (treeId, treeNode, clickFlag ){
// Normal selection
If (clickFlag = 1 ){
Parent.doc ument. getElementById ("coagencyId"). value = treeNode. id;
Parent.doc ument. getElementById ("parentId"). value = treeNode. pId;
Parent.doc ument. getElementById ("name"). value = treeNode. name;
$ ("# CoagencyId"). attr ("value", treeNode. id );
$ ("# ParentId"). attr ("value", treeNode. pId );
} Else {
// Unselect and leave the value Blank
$ ("# CoagencyId"). attr ("value", null );
$ ("# ParentId"). attr ("value", null );
}
Return (treeNode. click! = False );
}
// How to remove a node with the mouse
Function onClick (event, treeId, treeNode, clickFlag ){
// Displays the node details by default.
Parent. showCoagencyDetail ();
}
// Asynchronous loading requires a function
Function filter (treeId, parentNode, childNodes ){
If (! ChildNodes) return null;
For (var I = 0; I ChildNodes [I]. name = childNodes [I]. name. replace (/\. n/g ,'.');
}
Return childNodes;
}
// Asynchronous loading requires a function
Function beforeAsync (treeId, treeNode ){
Return treeNode? TreeNode. level <5: true;
}
// Initialization tree
$ (Document). ready (function (){
$. Fn. zTree. init ($ ("# coagencyTree"), settingOther );
});
SCRIPT






    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.