当前位置: 动力学知识库 > 问答 > 编程问答 >

Reload jsTree data return in an Ajax Request

问题描述:

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);

}

网友答案:

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.

$("div#tvJoinWorkspace").html(data);
$("#tvJoinWorkspace").jstree("destroy");
tvJoinWorkspaceTreeviewScriptInit(null);
网友答案:

What about this one? If you define your tree by

$("#jstree").jstree({ and you html is

<div id="tree">
  <div id="jstree">
  </div>
</div>

then you can

replace the <div id="jstree"></div> with something like <div id="jstree_ajax"></div>

分享给朋友:
您可能感兴趣的文章:
随机阅读: