简体   繁体   中英

Open a jstree in a jquery dialog box

I've looked for every possible example, but couldn't find a complete one. I'm new to jQuery and javascript in general - I'm a backend developer. I'm trying to display the html results of an ajax call inside a jstree in a dialog box, and don't have the first clue what I'm doing. This is what I've come up with so far - can someone tell me what I'm doing wrong? (I had to retype this vs copy/paste, so there may be some minor typos).

success: function(data) {
    $.getScript("js/jquery/jquery.jstree.js", function() {
        var $genericDialog = $("#genericDialog")
        $genericDialog.jstree({"html_data":data});
        $genericDialog.dialog({
            title: "ASDF",
            modal: true,
            width: 450,
            height: 700,
            buttons: {
                "OK": function() {
                         $genericDialog.dialog("close");
                     }
            }
        });
    });
},

From there documentation

 "html_data" : {
        "data" : "<li id='root'><a href='#'>Root node</a><ul><li><a href='#'>Child node</a></li></ul></li>"
    },

So make sure that the object you are passing to "html_data" is in the above format. ie your 'data' should be an object with "data" as its property.

Other than that, I don't see any problems with your code.

Update

http://jsfiddle.net/STA3c/7/

I have used your code. It seems to be working. Check if all the correct javascript files are loaded properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM