Test demo 2 of jquery and zTree tree structure, jqueryztree
Js Code: $ (function () {initTree ("dxTxl", CONST_URL.LOAD_DXTREE, "id", "yhzid"); // initialize the initTree ("yjTxl", CONST_URL.LOAD_YJTREE, "id", "yhzid"); // initialize the email address book} // construct zTreefunction initTree (zTreeID, url, id, pid) {var setting = {check: {enable: true // display checkbox}, data: {key: {name: "xm"}, simpleData: {enable: true, idKey: "id", pIdKey: "yhzid" }}, callback: {onCheck: getCheckedData // method triggered when the checkbox value is changed}; $. Ajax ({type: "get", dataType: "json", url: url, success: function (data) {$. fn. zTree. init ($ ("#" + zTreeID), setting, data. data) ;}}) ;}// trigger method function getCheckedData (e, treeId, treeNode) {if (treeNode. checked) {// check if (treeNode. isParent) {// determine whether it is a parent node var childrenNodes = treeNode. children; // obtain the child Node object if (childrenNodes) {$. each (childrenNodes, function () {setDxOrYj (this); // set the value to the input box}) ;}} else {setDxOrYj (TreeNode) ;}} else {// uncheck the operation if (treeNode. isParent) {var childrenNodes = treeNode. children; if (childrenNodes) {$. each (childrenNodes, function () {clearDxOrYj (this); // clear the value of the input box}) ;}} else {clearDxOrYj (treeNode );}}} // input the set value function setDxOrYj (treeNode) {if (treeNode. txllx = "001") {// Text Message Address Book if ($ ('# dxsxr '). val () = "") {$ ('# dxsxr '). val (treeNode. sj);} else {$ ('# dxsxr '). val ($ ('# dxsxr '). val () + ";" + treeNode. sj );}} Else if (treeNode. txllx = "002") {// email address book if ($ ('# yjsjr '). val () = "") {$ ('# yjsjr '). val (treeNode. dzyj);} else {$ ('# yjsjr '). val ($ ('# yjsjr '). val () + ";" + treeNode. dzyj) ;}}// clear the receiver input box value function clearDxOrYj (treeNode) {var data = ""; if (treeNode. txllx = "001") {// Text Message Address Book var dxdata = ($ ('# dxsxr '). val ()). split (";"); for (var I = 0; I <dxdata. length; I ++) {if (treeNode. sj! = Dxdata [I]) {if (data = "") {data + = dxdata [I];} else {data + = "; "+ dxdata [I] ;};}$ ('# dxsxr '). val (data);} else if (treeNode. txllx = "002") {// Email Address Book var yjdata =$ ('# yjsjr '). val (). split (";"); for (var I = 0; I <yjdata. length; I ++) {if (treeNode. dzyj! = Yjdata [I]) {if (data = "") {data + = yjdata [I];} else {data + = "; "+ yjdata [I] ;};}$ ('# yjsjr '). val (data );}}