关闭

asp.net1.1下权限配置系统从设计到实现(三)

824人阅读 评论(0) 收藏 举报
怎么用脚本实现TreeView的父子节点联动功能? 由于Firefox本身的特点,在实现时分别在IE下用脚本实现,在Firefox下用.cs代码实现。由于这两种浏览器兼容性实在不怎么好,艾!
       OK,废话少说,现在首先给出实现TreeView父子节点联动选种脚本方法:
function ChcekFuncNodes(e)
  {
            
var i=e.clickedNodeIndex;
            
var node=e.getTreeNode(i);
            
var NodeArray=node.getChildren();
            
if(NodeArray.length>0)
            {
                        
if(node.getAttribute("Checked"== true)
                        {
                                    
for(var i=0;i<NodeArray.length;i++)
                                    {
                                       CheckTreeNode(NodeArray[i],
true,false);
                                       GetSelectedFunctionPointID(NodeArray[i]);        
                                    }
                                    GetSelectedFunctionID(node);
                        }
                        
else
                        {
                                  
for(var i=0;i<NodeArray.length;i++)
                                    {
                                       CheckTreeNode(NodeArray[i],
false,false);        
                                    }
                         }
             }
             
else 
             {
                        
var ParentNode=node.getParent();
                        
if(ParentNode!=null)
                        {
                                    
if(node.getAttribute("Checked"== true)
                                    {        
                                              GetSelectedFunctionPointID(node);
                                              CheckTreeNode(ParentNode,
true,false);
                                              GetSelectedFunctionID(ParentNode);
                                    }
                                    
else
                                    {
                                            
if(AllChildTreeNodeSameCheck(ParentNode,false))
                                            {
                                                CheckTreeNode(ParentNode,
false,false);
                                            }
                                      }
                    }
                    
else
                    {
                        CheckTreeNode(node,
true,false);
                        GetSelectedFunctionID(node);
                    }
               }
      }
function CheckTreeNode(chilNode,isCheck,atuoSetChilTreeNode)
    {
 
            
if(chilNode!=null)
            { 
                        
//alert(chilNode);
                        chilNode.setAttribute('checked',isCheck);
                        
if(atuoSetChilTreeNode)
                        {
                        CheckChildTreeNode(chilNode,isCheck)
                        }
            }
   }
 function CheckChildTreeNode(Pnode,isCheck)
  {
            
if(Pnode!=null)
            {
                        
var arr=Pnode.getChildren();
                        
for(var i=0;i<arr.length;i++)
                        {
                         arr[i].setAttribute('checked',isCheck);
                        }
            }
  }
 function AllChildTreeNodeSameCheck(PareNode, value)
  {
         
if(PareNode!=null)
         {
                    
var chids=PareNode.getChildren();
                    
for(var i=0;i<chids.length;i++)
                    {
                                    
if(chids[i].getAttribute("Checked")!=value)
                                    {
                                      
return false;
                                    }
                      }
         }
          
return true;
  }
大家都知道,不用多讲,下面两个方法是纪录用户选中的FunctionID和FunctionPointID,通过隐藏控件传递给.cs文件使用,补充一下就是为什么我用document.getElementById('<%=hidenFunID.ClientID%>')而不用document.getElementById('hidenFunID')?原因是我的脚本是放在ascx文件中的(即UserControl中的)所以只能通过这种方式来找控件,否则就找不到哟!算是个小技巧吧 :)
 function GetSelectedFunctionID(nodes) 
     {
         
var hideFun = document.getElementById('<%=hidenFunID.ClientID%>');
         
var checkFun = hideFun.value;
         checkFun 
+= nodes.getAttribute("ID")+";";
         hideFun.value 
=checkFun;    
        
// alert(hideFun.value);
     }  
function GetSelectedFunctionPointID(nodes)
     {
         
var hideFunPoint = document.getElementById('<%=txtPointId.ClientID%>');
         
var checkFun = hideFunPoint.value;
         checkFun 
+= nodes.getAttribute("ID")+";";
         hideFunPoint.value 
=checkFun;    
         
//alert(hideFunPoint.value);
     }  
最后一步,让TreeView父子节点联动产生真正的效果,哈哈.................
private void Page_Load(object sender, System.EventArgs e)
        {
            
if(!
Page.IsPostBack )
            {
                 tvRoleFunctions.Attributes.Add("oncheck","ChcekFuncNodes(this)");
            }        
        }

下次写作预告:
怎么实现Select All  TreeView全部节点的功能?怎么实现展开和折叠自如?

http://jigee.cnblogs.com/archive/2006/06/09/421367.html#421589

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2287552次
    • 积分:26141
    • 等级:
    • 排名:第229名
    • 原创:1篇
    • 转载:1662篇
    • 译文:0篇
    • 评论:98条
    最新评论