简体   繁体   English

将动态Javascript树结构加载到JSP中

[英]Loading a Dynamic Javascript Tree Structure into a JSP

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. 目前,我正在使用destroydrop树,并且可以单独使用它,但是如果我要构建该树并将其放入网页中,则我的页面将被覆盖,因为它使用document.write(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树 Nitobi Completeui framework has both client and server sides. Nitobi Completeui框架同时具有客户端和服务器端。

You can find samples in code repository . 您可以在代码存储库中找到示例。

Thanks much for the help. 非常感谢您的帮助。 I ended up just overriding document.write as such 我最终只是覆盖了document.write这样

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! 再次感谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM