If you want to load a json file locally and dynamically Insert the file to ul through events, you will encounter a small bug. The following section will explain how to load the json file locally, A small bug occurs when an event is dynamically inserted into ul.
The code in html is like this.
Code in js
$(".next-menu:nth-child(1) a").click(function() {var $IDstr = $(this).attr("id"),$treeIDNum = parseInt($(this).attr("treeID")),jsonURL = "json/" + $IDstr + ".json",node;addAttr2Tree(jsonURL);changeImgSrc($treeIDNum);});});function changeImgSrc(nodeID){var node = $("#tt").tree('find', nodeID);if(node){$("#tt").tree('select', node.target);}if (node.attributes) {$("#img-box").attr("src", node.attributes.url);}}function addAttr2Tree(URL){$("#tt").tree({url: URL,method: "get",animate: true,lines: true});}
The above code is used to dynamically load the tree content by clicking a button event. addAttr2Tree is used to add the corresponding local json data when the button is clicked to the ul tag in html, changeImgSrc is used to select tree nodes and load images. However, no matter how you debug them, an error always occurs.
So
$(".next-menu:nth-child(1) a").click(function() {var $IDstr = $(this).attr("id"),$treeIDNum = parseInt($(this).attr("treeID")),jsonURL = "json/" + $IDstr + ".json",node;addAttr2Tree(jsonURL);$("#tt").tree({onLoadSuccess: function(){changeImgSrc($treeIDNum);}});});
The code is changed to this.
The above section describes how to resolve the jQuery Easyui asynchronous tree loading problem. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. I would like to thank you for your support for PHP chinnet!