jQuery MiniUI

标题: 左侧的菜单树如何动态生成? [打印本页]

作者: dongbin    时间: 2012-8-3 15:41:43     标题: 左侧的菜单树如何动态生成?

后台是servlet获得json数据,miniui模版的左侧树菜单是静态代码,现在我尝试用ajax接收到的数据采用循环的方式画出来,但是虽然能画出数据,但是没有原来的效果,不知道咋回事啊?
关键代码:这部分我是在body 上onload引用的。
function ajaxrequest(url,methodtype,con,parameter,functionName,obj){
        var xmlhttp=getajaxHttp();
        xmlhttp.onreadystatechange=function(){
                if(xmlhttp.readyState==4){
                        //HTTP响应已经完全接收才调用
                        var responseContent = xmlhttp.responseText;
                        eval("var objson="+ responseContent);
                        var clusternum=objson.clusters_info.length;
                       
               
                        alert("ready,go!!!!!");
                        var demoTree= document.getElementById("demoTree");
                       
                        for(i=0;i<clusternum;i++){
                                var li=document.createElement("li");
                                var span=document.createElement("span");
                                span.setAttribute("expanded","false");
                                span.innerHTML=objson.clusters_info[i].clustername;
                                li.appendChild(span);
                                demoTree.appendChild(li);
                        }
                }
        };
        xmlhttp.open(methodtype,url,con);
        xmlhttp.send(parameter);
}


作者: niko    时间: 2012-8-3 16:05:06

生成树,参考此示例:
http://www.miniui.com/demo/#src=tree/list2tree.html

你做的太复杂了。。。
作者: dongbin    时间: 2012-8-4 18:58:09

niko 发表于 2012-8-3 16:05
生成树,参考此示例:
http://www.miniui.com/demo/#src=tree/list2tree.html

<ul id="tree1" class="mini-tree" url="../data/listTree.txt" style="width:200px;padding:5px;"
        showTreeIcon="true" textField="text" idField="id" parentField="pid" resultAsTree="false"  
        >
    </ul>
这段代码就生成了一棵树,请问这个 "../data/listTree.txt"里的内容就是树的内容吗?
那txt文件里面是什么结构啊 ?下载的代码里面有吗?
作者: dongbin    时间: 2012-8-4 20:47:55

niko 发表于 2012-8-3 16:05
生成树,参考此示例:
http://www.miniui.com/demo/#src=tree/list2tree.html

我已经找到这个东西了,麻烦再问一句啊,怎么自动生成多级菜单呢?
作者: dongbin    时间: 2012-8-4 23:37:17

niko 发表于 2012-8-3 16:05
生成树,参考此示例:
http://www.miniui.com/demo/#src=tree/list2tree.html

PluSoft.Utils.*这个jar包能传我一个吗
作者: niko    时间: 2012-8-5 09:15:46

你生成一个数组,由id和pid体现父子关系,就是多级数据了。
作者: dongbin    时间: 2012-8-5 19:21:25

niko 发表于 2012-8-5 09:15
你生成一个数组,由id和pid体现父子关系,就是多级数据了。

恩,多级的问题已经解决了;
但现在有个问题啊,自动产生的这些树叶,我怎么加上链接呢?
作者: niko    时间: 2012-8-6 08:01:43

参考树节点绘制示例:http://www.miniui.com/demo/#src=tree/drawnode.html




欢迎光临 jQuery MiniUI (http://miniui.com/discuss/) Powered by Discuz! X2