开发者

Loading a Dynamic Javascript Tree Structure into a JSP

开发者 https://www.devze.com 2023-04-05 16:34 出处:网络
So I am wanting to read a database, and then form a tree structure and put it in my webpage. I am using the destroydrop tree at the moment, and I can 开发者_运维问答get it to work on its own, but if I

So I am wanting to read a database, and then form a tree structure and put it in my webpage. I am using the destroydrop tree at the moment, and I can 开发者_运维问答get it to work on its own, but if I want to build the tree and then put it in my webpage, then my page gets overwritten because it uses document.write(tree) to create the tree. I've also tried some other trees which all have the same issue. Anyone know of a tree structure that I can dynamically add to my page without overwriting what is on there? Thanks!


You can try nitobi tree. Nitobi Completeui framework has both client and server sides.

You can find samples in code repository.


Thanks much for the help. I ended up just overriding document.write as such

document.write = function(){
    document.getElementById("MyDiv").innerHTML = arguments[0];
}

function getTreeStruct() {
new Ajax.Request('MainServlet', {
    method: 'POST',
    parameters: "action=getTreeStruct",
    onSuccess: function(transport) {

        d = new dTree('d');
        d.add(0, -1, 'Root Element');
        //contains data queried from database to be inserted into the tree.
        var responseArray = transport.responseText.split("|");
        //Add each element to the tree object
        iterate1DArray(function(x) {
            var tempArray = x.split(",");
            if(tempArray[1] != undefined
                    && !(tempArray[0] == 0 && tempArray[1] ==0)){
                d.add(tempArray[0], tempArray[1], tempArray[2]);
            }
        }, responseArray);

        document.write(d);

    }
});

}

function iterate1DArray(func, array) {
    for( var i = 0; i < array.length; i++){
        array[i] = func(array[i]);
    }
}

I did not include the code for the tree, but it can be found here. Just thought I would put this on here in case anyone else has this type of issue. Thanks again for all your help!

0

精彩评论

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