Analysis on Asynchronous tree loading in jQueryEasyui

Source: Internet
Author: User
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',;}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.


    $(".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!

    Related Article

    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: 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.