在jQuery对话框中打开jstree [英] Open a jstree in a jquery dialog box
问题描述
我一直在寻找所有可能的示例,但找不到完整的示例.我是jQuery和javascript的新手-我是后端开发人员.我试图在对话框中的jstree内显示ajax调用的html结果,并且不知道我在做什么.到目前为止,这是我要提出的-有人可以告诉我我做错了什么吗? (我必须重新输入此vs复制/粘贴内容,因此可能会有一些小的错别字.)
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");
}
}
});
});
},
推荐答案
从此处获取文档
"html_data" : {
"data" : "<li id='root'><a href='#'>Root node</a><ul><li><a href='#'>Child node</a></li></ul></li>"
},
因此,请确保您要传递给"html_data"的对象采用上述格式.即您的数据"应该是一个以数据"为属性的对象.
So make sure that the object you are passing to "html_data" is in the above format. i.e your 'data' should be an object with "data" as its property.
除此之外,我的代码没有任何问题.
Other than that, I don't see any problems with your code.
更新
我已经使用了您的代码.它似乎正在工作.检查所有正确的javascript文件是否均已正确加载.
I have used your code. It seems to be working. Check if all the correct javascript files are loaded properly.
这篇关于在jQuery对话框中打开jstree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!