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

发布于 2024-12-05 05:23:32 字数 190 浏览 1 评论 0原文

所以我想读取一个数据库,然后形成一个树结构并将其放入我的网页中。我目前正在使用 destroydrop 树,我可以让它自行工作,但是如果我想构建树然后将其放入我的网页中,那么我的页面会被覆盖,因为它使用 document.write(tree )来创建树。我也尝试过其他一些树,它们都有同样的问题。有人知道我可以动态添加到我的页面而不覆盖那里的内容的树结构吗?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

压抑⊿情绪 2024-12-12 05:23:32

您可以尝试 nitobi 树。 Nitobi Completeui 框架有客户端和服务器端。

您可以在代码存储库中找到示例。

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

You can find samples in code repository.

我最亲爱的 2024-12-12 05:23:32

非常感谢您的帮助。我最终只是覆盖了 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]);
    }
}

我没有包含树的代码,但可以在 here 找到它。只是想我会把它放在这里以防其他人遇到此类问题。再次感谢您的所有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文