重新加载 Ajax 请求中返回的 jsTree 数据
我的 jsTree 包含在树加载时设置的 html 数据(请参阅下面的 javascript)。这工作正常。但是,我希望能够根据某些用户操作在 Ajax 请求中重新加载整个树。我基本上需要重新加载从 Ajax 请求返回的所有树数据。这可能吗?
我当前的代码如下:
function setJoinType(node, joinType) {
$.ajax({
type: "POST",
url: "qbwizard.aspx/SetJoinType",
contentType: "application/json; charset=utf-8",
data: "{'alias': '" + node[0].id + "', 'joinType': '" + joinType + "'}",
dataType: "json",
success: RedrawJoinSummary,
error: AjaxFailed
});
return true;
}
function RedrawJoinSummary(data) {
//$("#tvJoinSummary").jstree('destroy');
$("#tvJoinSummary").jstree("html", data.d);
$("#tvJoinSummary").jstree("refresh", -1);
}
My jsTree contains html data that is set when the tree loads (see javascript below). This works correctly. However, I want to be able to reload the entire tree in an Ajax request based on certain user actions. I basically need to reload all the tree data returned from the Ajax request. Is this possible?
My current code is below:
function setJoinType(node, joinType) {
$.ajax({
type: "POST",
url: "qbwizard.aspx/SetJoinType",
contentType: "application/json; charset=utf-8",
data: "{'alias': '" + node[0].id + "', 'joinType': '" + joinType + "'}",
dataType: "json",
success: RedrawJoinSummary,
error: AjaxFailed
});
return true;
}
function RedrawJoinSummary(data) {
//$("#tvJoinSummary").jstree('destroy');
$("#tvJoinSummary").jstree("html", data.d);
$("#tvJoinSummary").jstree("refresh", -1);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谢谢拉德克。
实际上,我通过将 jstree 初始化代码放入函数(tvJoinWorkspaceTreeviewScriptInit)中,然后在重置 html 后调用该函数来实现此目的。可能是节点都失去了它们的状态(打开/关闭)。我决定使用 Ajax 回调和 javascript 再次构建树,因为它最终更容易做到。
Thanks Radek.
I actually got this to work by putting the jstree intialization code into a function (tvJoinWorkspaceTreeviewScriptInit) and then calling that function after resetting the html. The probably is that the nodes all lose their state (opened / closed). I decided to use Ajax callbacks and javascript to build the tree again because it ended up being much easier to do.
这个呢?如果您通过
$("#jstree").jstree({
定义树并且您的 html 是
,那么您可以
替换
;
类似于What about this one? If you define your tree by
$("#jstree").jstree({
and you html isthen you can
replace the
<div id="jstree"></div>
with something like<div id="jstree_ajax"></div>