Home  >  Article  >  Web Front-end  >  JQuery writes dynamic tree sample code_jquery

JQuery writes dynamic tree sample code_jquery

WBOY
WBOYOriginal
2016-05-16 17:27:331063browse
Copy code The code is as follows:

// Business type tree
var settingOther = {
edit: {
enable: false
},
// Asynchronous loading 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.document.getElementById("coagencyId").value=treeNode.id;
parent.document.getElementById("parentId").value=treeNode.pId;
parent.document.getElementById("name") .value=treeNode.name;
$("#coagencyId").attr("value",treeNode.id);
$("#parentId").attr("value",treeNode.pId) ;
}else{
// Uncheck and leave the value blank
$("#coagencyId").attr("value",null);
$("#parentId").attr ("value",null);
}
return (treeNode.click != false);
}
// Method to remove the node with the mouse
function onClick(event, treeId, treeNode , clickFlag) {
// The default execution method displays the detailed information of the node
parent.showCoagencyDetail();
}
// Asynchronous loading needs to be the function
function filter(treeId, parentNode , childNodes) {
if (!childNodes) return null;
for (var i=0; ichildNodes[i].name = childNodes[i].name .replace(/.n/g, '.');
}
return childNodes;
}
// Asynchronous loading needs to be a function
function beforeAsync(treeId, treeNode) {
return treeNode ? treeNode.level < 5 : true;
}
//Initialize tree
$(document).ready(function(){
$.fn.zTree.init( $("#coagencyTree"),settingOther);
});







    < ;/div>
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn