Initial data for Ztree var znodes = [ {id:1, pid:0, Name: "Match"}, {id:2, pid:0, Name: "Match 2"}, {id:3, pid:0, Name: "Match 4343"}, {id:6, pid:0, Name: "Match 444"}, {id:4, pid:0, name: "Hebei Province", Open:true}, {id:41, Pid:4, Name: "Shijiazhuang"}, {id:42, Pid:4, Name: "Baoding"}, {id:43, Pid:4, Name: "Handan"}, {id:44, Pid:4, Name: "Chengde"}, {id:5, pid:0, name: "Guangdong Province", open:true}, {id:51, Pid:5, Name: "Guangzhou"}, {id:52, Pid:5, Name: "Shenzhen"}, {id:53, Pid:5, Name: "Dongguan"}, {id:54, Pid:5, Name: "Foshan"}, {id:6, pid:0, Name: "Fujian Province", Open:true}, {id:61, Pid:6, Name: "Fuzhou"}, {id:62, Pid:6, Name: "Xiamen"}, {id:63, Pid:6, Name: "Quanzhou"}, {id:64, Pid:6, Name: "Sanming"} ]; Click on a node and assign the name of the node to the Value text box function OnClick (E, Treeid, TreeNode) { var ztree = $.fn.ztree.getztreeobj ("Treedemo"); Get the selected node var nodes = Ztree.getselectednodes (), v = ""; Sort by ID Nodes.sort (function compare (A, b) {return a.id-b.id;}); for (var i = 0, L = nodes.length i < l; i++) { V + + nodes[i].name + ","; } Displays the name of the selected node in a text box if (v.length > 0) v = v.substring (0, v.length-1); var cityobj = $ ("#citySel"); Cityobj.attr ("value", V); Hide Ztree Hidemenu (); return false; } Show Tree function ShowMenu () { var cityobj = $ ("#citySel"); var Cityoffset = $ ("#citySel"). Offset (); $ ("#menuContent"). CSS ({left:cityOffset.left + "px", Top:cityOffset.top + cityobj.outerheight () + "px"}). Slidedown ("FA St "); } Hide Tree function Hidemenu () { $ ("#menuContent"). Fadeout ("fast"); $ ("body"). Unbind ("MouseDown", Onbodydown); } Restore initial data for Ztree function Initialztree () { $.fn.ztree.init ($ ("#treeDemo"), setting, znodes); } Automatic matching of tree nodes to Fuzzy Lookup based on keyword input of text box function Automatch (txtobj) { if (TxtObj.value.length > 0) { Initialztree (); var ztree = $.fn.ztree.getztreeobj ("Treedemo"); var nodelist = ztree.getnodesbyparamfuzzy ("name", Txtobj.value, false); var Nodearr = new Array (); This is done in order to avoid the parent node fuzzy matching data will automatically be brought into all its child nodes for (var i = 0; i < nodelist.length; i++) { var obj = new Object (); Obj.id = nodelist[i].id; Obj.pid = Nodelist[i].pid; Obj.name = Nodelist[i].name; Nodearr.push (obj); } Update the found NodeList node to Ztree $.fn.ztree.init ($ ("#treeDemo"), setting, Nodearr); ShowMenu (); } else { Hide Tree Hidemenu (); Initialztree (); } } |