关于梅花雪的js树

最近一段时间,为了学习java,天天在看别人的框架,为了实现一颗树,找到了一个改写梅花雪的js,下面是一个基本的结构

2007-11-03_225539.JPG

ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ page language="java" import="java.util.*" pageEncoding="GBK" %>
ExpandedBlockStart.gifContractedBlock.gif
<% dot.gif
InBlock.gif
String path = request.getContextPath();
ExpandedBlockEnd.gif
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
None.gif
%>
None.gif
None.gif
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
None.gif
< html >
None.gif  
< head >
None.gif    
< base  href ="<%=basePath%>" >
None.gif    
None.gif    
< title > My JSP 'MyJsp.jsp' starting page </ title >
None.gif    
None.gif    
< meta  http-equiv ="pragma"  content ="no-cache" >
None.gif    
< meta  http-equiv ="cache-control"  content ="no-cache" >
None.gif    
< meta  http-equiv ="expires"  content ="0" >     
None.gif    
< meta  http-equiv ="keywords"  content ="keyword1,keyword2,keyword3" >
None.gif    
< meta  http-equiv ="description"  content ="This is my page" >
None.gif    
< script  language ="javaScript"  src ="MzTreeView12.js" ></ script >
ExpandedBlockStart.gifContractedBlock.gif
< style > dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gifbody 
{dot.gif}{font:normal 12px 宋体}
ExpandedSubBlockStart.gifContractedSubBlock.gifa.MzTreeview 
/**//* TreeView 链接的基本样式 */ {dot.gif}{ cursor: hand; color: #000080; margin-top: 5px; padding: 2 1 0 2; text-decoration: none; }
ExpandedSubBlockStart.gifContractedSubBlock.gif.MzTreeview a.select 
/**//* TreeView 链接被选中时的样式 */ {dot.gif}{ color: highlighttext; background-color: highlight; }
ExpandedSubBlockStart.gifContractedSubBlock.gif#kkk input 
{dot.gif}{
InBlock.gifvertical-align
:middle;
ExpandedSubBlockEnd.gif
}

ExpandedSubBlockStart.gifContractedSubBlock.gif.MzTreeViewRow 
{dot.gif}{border:none;width:500px;padding:0px;margin:0px;border-collapse:collapse}
ExpandedSubBlockStart.gifContractedSubBlock.gif.MzTreeViewCell0 
{dot.gif}{border-bottom:1px solid #CCCCCC;padding:0px;margin:0px;}
ExpandedSubBlockStart.gifContractedSubBlock.gif.MzTreeViewCell1 
{dot.gif}{border-bottom:1px solid #CCCCCC;border-left:1px solid #CCCCCC;width:200px;padding:0px;margin:0px;}
None.gif
</ style >
None.gif    
< script  type ="text/javascript"  src ="/HAS/info/js/MzTreeView12.js" ></ script >
None.gif    
None.gif    
None.gif  
</ head >
None.gif  
None.gif  
< body >
None.gif    
< h3 > MzTreeView + CheckBox 复选框 + 自定义表格 演示 (MzTreeView v1.2 www.lxasp.com 修改版) </ h3 >
None.gif
None.gif
None.gif
< table  class ='MzTreeViewRow'  style ="background:#EEEEEE;border-top:1px solid #CCCCCC;" >< tr >< th  class ='MzTreeViewCell0' > </ th >< th  class ='MzTreeViewCell1' > ID </ th ></ tr ></ table >
None.gif
None.gif
< div  id ="kkk" ></ div >
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif    
< script  language ="javascript"  type ="text/javascript" > dot.gif
InBlock.gif    
<!--
InBlock.gif    
//var MzTreeViewTH="<table class='MzTreeViewRow'><tr><td class='MzTreeViewCell0'>";
InBlock.gif
    //var MzTreeViewTD="\"</td><td class='MzTreeViewCell1'>\"+ sid +\"</td></tr></table>\"";
InBlock.gif
    
InBlock.gif    window.tree 
= new MzTreeView("tree");
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*
InBlock.gif    tree.icons["property"] = "property.gif";
InBlock.gif    tree.icons["css"] = "collection.gif";
InBlock.gif    tree.icons["event"] = "collection.gif";
InBlock.gif    tree.icons["book"]  = "book.gif";
InBlock.gif    tree.iconsExpand["book"] = "bookopen.gif"; //展开时对应的图片
ExpandedSubBlockEnd.gif    
*/

InBlock.gif    tree.setIconPath(
"/HAS/info/images/treeimages/"); //可用相对路径
InBlock.gif
    tree.N["0_SH8900000000"= "ctrl:sel;checked:1;T:系统管理;"
InBlock.gif    tree.N[
"SH8900000000_SH8901000000"= "ctrl:sel;checked:1;T:文书模板管理"
InBlock.gif    tree.N[
"SH8900000000_SH8902000000"= "ctrl:sel;checked:0;T:自定义流程管理"
InBlock.gif    tree.N[
"SH8900000000_SH8903000000"= "ctrl:sel;checked:1;T:质量考核因素"
InBlock.gif    tree.N[
"SH8900000000_SH8904000000"= "ctrl:sel;checked:1;T:节假日管理"
InBlock.gif    tree.N[
"SH8900000000_SH8905000000"= "ctrl:sel;checked:1;T:事项管理"
InBlock.gif    tree.N[
"SH8900000000_SH8906000000"= "ctrl:sel;checked:1;T:用户及权限管理"
InBlock.gif    tree.N[
"SH8900000000_SH8907000000"= "ctrl:sel;checked:1;T:组织机构管理"
InBlock.gif    tree.N[
"SH8906000000_SH8906010000"= "ctrl:sel;checked:1;T:添加新用户"
InBlock.gif    tree.N[
"SH8907000000_SH8907010000"= "ctrl:sel;checked:1;T:添加组织机构"
InBlock.gif    tree.N[
"SH8906000000_SH8906020000"= "ctrl:sel;checked:0;T:用户管理"
InBlock.gif    tree.N[
"SH8907000000_SH8907020000"= "ctrl:sel;checked:0;T:组织机构管理"
InBlock.gif    tree.N[
"SH8906000000_SH8906030000"= "ctrl:sel;checked:1;T:添加新角色"
InBlock.gif    tree.N[
"SH8906000000_SH8906040000"= "ctrl:sel;checked:1;T:系统角色管理"
InBlock.gif
InBlock.gif    tree.setURL(
"#");
InBlock.gif    tree.wordLine 
= false;
InBlock.gif    tree.setTarget(
"main");
InBlock.gif    document.getElementById(
"kkk").innerHTML=tree.toString();
InBlock.gif    tree.expandAll();
InBlock.gif    
InBlock.gif    
//alert(document.getElementsByTagName("head")[0].innerHTML);
InBlock.gif
    //alert(document.getElementById("kkk").innerHTML);
InBlock.gif
    
InBlock.gif    
function showsel()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var es=document.getElementsByName("sel");
InBlock.gif        
var out="";
InBlock.gif        
for(var i=0;i<es.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (es[i].checked) out+=es[i].value+"\n";
ExpandedSubBlockEnd.gif        }

InBlock.gif        alert(out);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
//-->
ExpandedBlockEnd.gif
    
</ script >
None.gif
< p >
None.gif
< input  type ="button"  onclick ='showsel()'  value ='显示选中'  />
None.gif
</ p >
None.gif  
</ body >
None.gif
</ html >
None.gif


部门表结构:
编号      名称           上级
bianhao  mingcheng  shangji


在action中
ExpandedBlockStart.gif ContractedBlock.gif /** */ /**
InBlock.gif     * 得到部门
InBlock.gif     * 
@param mapping
InBlock.gif     * 
@param form
InBlock.gif     * 
@param request
InBlock.gif     * 
@param response
InBlock.gif     * 
@return
ExpandedBlockEnd.gif     
*/

None.gif    
public  ActionForward getBuMen(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif
InBlock.gif
//        实现注入
InBlock.gif
         UserManagerService userManagerService = GlobalService.getUserManagerService();
InBlock.gif         
InBlock.gif         List list
=userManagerService.getBuMen();
InBlock.gif         
InBlock.gif
InBlock.gif         Bumen bm
=new Bumen();
InBlock.gif        StringBuffer str
=new StringBuffer();
InBlock.gif        
InBlock.gif        
//图片路径
InBlock.gif
        str.append("tree.setIconPath('/HAS/info/images/treeimages/');");
InBlock.gif        str.append(
"\n");
InBlock.gif        
InBlock.gif         Iterator iterator 
= list.iterator(); 
InBlock.gif         
while(iterator.hasNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif{
InBlock.gif            
ExpandedSubBlockStart.gifContractedSubBlock.gif             
trydot.gif{
InBlock.gif                 Object[] obj 
= (Object[])iterator.next();
InBlock.gif                 String bianhao 
= obj[0].toString();
InBlock.gif                 String mingcheng 
= obj[1].toString();
InBlock.gif                 String shangji 
= obj[2].toString();
InBlock.gif                 
InBlock.gif                 bm.setBianhao(bianhao);
InBlock.gif                 bm.setMingcheng(mingcheng);
InBlock.gif                 bm.setShangji(shangji);
ExpandedSubBlockEnd.gif             }

ExpandedSubBlockStart.gifContractedSubBlock.gif             
catch(Exception e)dot.gif{
InBlock.gif                e.printStackTrace(); 
ExpandedSubBlockEnd.gif             }

InBlock.gif             
InBlock.gif             
if(bm.getBianhao().substring(1,12).equals("00000000000"))
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif                 str.append(
"tree.N['0");
InBlock.gif                 str.append(
"_");
InBlock.gif                 str.append(bm.getBianhao());
InBlock.gif                 str.append(
"']");
InBlock.gif                 str.append(
"=");
InBlock.gif                 str.append(
"'ctrl:sel;checked:0;T:"+bm.getMingcheng()+"'");
InBlock.gif                 str.append(
"\n");
ExpandedSubBlockEnd.gif             }

InBlock.gif             
else
ExpandedSubBlockStart.gifContractedSubBlock.gif             
dot.gif{
InBlock.gif                 str.append(
"tree.N['");
InBlock.gif                 str.append(bm.getShangji());
InBlock.gif                 str.append(
"_");
InBlock.gif                 str.append(bm.getBianhao());
InBlock.gif                 str.append(
"']");
InBlock.gif                 str.append(
"=");
InBlock.gif                 str.append(
"'ctrl:sel;checked:0;T:"+bm.getMingcheng()+"'");
InBlock.gif                 str.append(
"\n");
ExpandedSubBlockEnd.gif             }

InBlock.gif
InBlock.gif         
InBlock.gif         
InBlock.gif        
InBlock.gif        
//第二种用法
InBlock.gif         
InBlock.gif
//         for(int i = 0; i < list.size(); i++)
InBlock.gif
//         {
InBlock.gif
//             Bumen bm = (Bumen)list.get(i);
InBlock.gif
//             
InBlock.gif
//             if(bm.getBianhao().substring(1,12).equals("00000000000"))
InBlock.gif
//                  {
InBlock.gif
//                      str.append("tree.N['0");
InBlock.gif
//                      //str.append(bm.getShangji());
InBlock.gif
//                      str.append("_");
InBlock.gif
//                      str.append(bm.getBianhao());
InBlock.gif
//         
InBlock.gif
//                      str.append("']");
InBlock.gif
//                      str.append("=");
InBlock.gif
//         
InBlock.gif
//                      str.append("'ctrl:sel;checked:0;T:"+bm.getMingcheng()+"'");
InBlock.gif
//         
InBlock.gif
//                      str.append("\n");
InBlock.gif
//                  }
InBlock.gif
//                  else
InBlock.gif
//                  {
InBlock.gif
//                      str.append("tree.N['");
InBlock.gif
//                      str.append(bm.getShangji());
InBlock.gif
//                      str.append("_");
InBlock.gif
//                      str.append(bm.getBianhao());
InBlock.gif
//         
InBlock.gif
//                      str.append("']");
InBlock.gif
//                      str.append("=");
InBlock.gif
//         
InBlock.gif
//                      str.append("'ctrl:sel;checked:0;T:"+bm.getMingcheng()+"'");
InBlock.gif
//         
InBlock.gif
//                      str.append("\n");
InBlock.gif
//                  }
InBlock.gif
//             
ExpandedSubBlockEnd.gif
         }

InBlock.gif         
InBlock.gif         
InBlock.gif         str.append(
"tree.setURL('#');");
InBlock.gif         str.append(
"\n");
InBlock.gif         str.append(
"tree.wordLine=false;");
InBlock.gif         str.append(
"\n");
InBlock.gif         str.append(
"tree.setTarget('main');");
InBlock.gif         str.append(
"\n");
InBlock.gif         
InBlock.gif
InBlock.gif         
InBlock.gif        request.setAttribute(
"BUMENTREE", str); 
InBlock.gif        request.setAttribute(
"LISTBUMEN", list);
InBlock.gif        
return mapping.findForward("bumen");
ExpandedBlockEnd.gif    }

None.gif
None.gif}

其中是使用dao的注入方式,来得到部门

js下载地址:
http://www.cnbolgs.com/Files/huazi4995/MzTreeView12.js

转载于:https://www.cnblogs.com/huazi4995/archive/2007/11/03/948454.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值