Thomson-Blog ( 学习,学习,再学习;努力,努力,再努力。)
在学习的路上不断成长,成功之路就在脚下。
jsp文件
/*
*level:所在�哟�    description: 结点名称
*
*/
       String s2 = "<SCRIPT LANGUAGE=\"JavaScript\">";
        s2 = s2 + "ImgDir = \"images/menu/\";";
        s2 = s2 + "SetFolderIcon(\"user.gif\");";
        s2 = s2 + "treeMenuAddItem(0, \"�湫筒���\");";
        s2 = s2 + "SetFolderIcon();";
        DBConnect dbconnect = new DBConnect();
        dbconnect.prepareStatement("Select * from tree order by code asc");
        ResultSet resultset = dbconnect.executeQuery();

while(resultset.next())
       {
       String level = resultset.getString("level");
       String description = resultset.getString("description");
      
        //这一行有问题,如果去掉可以显示树,但我要从数据库中去数据动态显示树的层次,
         确定数据库可以成功输出level和description但用参数传给javascript时就无法显示树了。
       s2 = s2 + "treeMenuAddItem("+level+", "+description+");";
      
       }
    s2 = s2 + "</script>";
    out.println(s2);
------------------javascript文件
/*
*level:�哟�    text: 描述内容   url:�B接
*target: 打�_位置   icon:�D��
*/
function treeMenuAddItem(level, text, url, target, icon)
{
        
        if (!target)
        {
                parentLevel=level;
                if(level)
                        auxs[level] = auxs[level - 1].addChild(new Folder(text, url));
                else auxs[0] = new Folder(text);
        }
        else
        {
                if(level>parentLevel + 1)level = parentLevel + 1;
                auxs[level - 1].addChild(new Item(text, "'"+url+"' target=\"" + target + "\"",

icon));
        }
}
posted on 2008-06-18 11:27  Thomson-Blog  阅读(601)  评论(0编辑  收藏  举报