开发者

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 + 开发者_如何学JAVA"', '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>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜