当前位置: 首页 > 工具软件 > CheckTree > 使用案例 >

checktree

蒯慈
2023-12-01

public class CheckTreeWrite {
 private static DaoFactory dao = HibernateDaoFactory.getDaoFactory();
 static String scripthead = " ";
 static String scriptend = " ";
 static String scriptbody = "";
 
 public static void clear() {
  scripthead = " ";
  scriptend = " function changeAllChild(parent){for(var i=0;i<parent.childNodes.length;i++){ parent.childNodes[i].getUI().onRender();  parent.childNodes[i].getUI().toggleCheck (parent.getUI().isChecked ());  changeAllChild(parent.childNodes[i]) }   };";
  scriptend += " function changeAllParent(child){if(child==root){return;}; if(child.getUI().checkbox.checked==true){ child.parentNode .getUI().checkbox.checked=true;}  changeAllParent(child.parentNode) ;   };";
  scriptend += " function removeAllcheckchange(parent){for(var i=0;i<parent.childNodes.length;i++){  parent.removeListener(/"checkchange/",changebottom ); removeAllcheckchange(parent.childNodes[i]) }   };";
  scriptend += " function addAllcheckchange(parent){for(var i=0;i<parent.childNodes.length;i++){  parent.addListener(/"checkchange/",changebottom ); addAllcheckchange(parent.childNodes[i]) }   };";
  scriptbody = "";
 }
 
 
 public static String getCheckBoxTree(List<TreeItem> list, String rootname,
   String url) {
  clear();
  if (rootname == null || rootname.equals("")) {
   rootname = "root";
  }

  if (url == null || url.equals("")) {
   url = "javascript:void(0)";
  }
  scriptbody += "var root=new Ext.tree.TreeNode({listeners:{        'checkchange':function changebottom()         {  changeAllChild(root)  } },checked:false,id:/"root/",text:/""
    + " "+rootname + " /",href:'" + url
    + "',hrefTarget:'rightFrame',expanded:true});/n";

  TreeItem it;
  
  
  HashMap deptidMap=new HashMap();
  for (int i = 0; i < list.size(); i++) {
   it = (TreeItem) list.get(i);
  
   deptidMap.put(it.getItemId(), it);//放入hashMap,用于子结点引用
   if (it.getItemLev() == 1) {
    AddTreeItem(it,false);//根结点

   } else {
    
      AddTreeItem(it,(TreeItem)deptidMap.get(it.getItemRef()),false);
    

   }

  }

  return scripthead + scriptbody + scriptend;
 }
 
 
 public static TreeItem AddTreeItem(TreeItem po, boolean tar) {
  scriptbody += "var obj" + po.getItemId()
  + "=new Ext.tree.TreeNode({listeners:{        'checkchange':function changebottom()         {  changeAllChild(obj" + po.getItemId()+")  } },checked:false,id:/"" + po.getItemId()
  + "/",text:/" "+po.getItemName() + " /",href:/"" + po.getUrl();
  if (tar)
   scriptbody += "/",hrefTarget:'rightFrame'});/n";
  else
   scriptbody += "/"});/n";
  
  scriptbody += "root.appendChild(obj" + po.getItemId() + ");/n";
  
  //自身有子结点列表
  if(po.getTreeItems()!=null&&po.getTreeItems().size()>0)
  {
   for(int i=0;i<po.getTreeItems().size();i++)
   {
   AddTreeItem((TreeItem)po.getTreeItems().get(i),po, false);
   }
  }
  
  return po;
  
 }
 
 public static TreeItem AddTreeItem(TreeItem po, TreeItem parent, boolean tar) {
  scriptbody += "var obj" + po.getItemId()
  + "=new Ext.tree.TreeNode({listeners:{        'checkchange':function changebottom()         {  changeAllChild(obj" + po.getItemId()+")  } },checked:false,id:/"" + po.getItemId()
  + "/",text:/""+po.getItemName() + "/",href:/"" + po.getUrl();
  if (tar)
   scriptbody += "/",hrefTarget:'rightFrame'});/n";
  else
   scriptbody += "/"});/n";
  
  scriptbody += "obj" + parent.getItemId() + ".appendChild(obj"
  + po.getItemId() + ");/n";
  
  
  //自身有子结点列表
  if(po.getTreeItems()!=null&&po.getTreeItems().size()>0)
  {
   for(int i=0;i<po.getTreeItems().size();i++)
   {
   AddTreeItem((TreeItem)po.getTreeItems().get(i),po, false);
   }
  }
  
  
  return po;
  
 }
 


 
 
 
 
 
 
}
--------------------------

 

Ext.onReady(function(){

 var root=new Ext.tree.TreeNode({listeners:{        'checkchange':function changebottom()         {  changeAllChild(root)  } },checked:false,id:"root",text:" 模块列表 ",href:'/sys/sysnodeAction.action',hrefTarget:'rightFrame',expanded:true});
var obj01=new Ext.tree.TreeNode({listeners:{        'checkchange':function changebottom()         {  changeAllChild(obj01)  } },checked:false,id:"01",text:" 系统管理 ",href:"javascript:void(0)"});
root.appendChild(obj01);
var obj02=new Ext.tree.TreeNode({listeners:{        'checkchange':function changebottom()         {  changeAllChild(obj02)  } },checked:false,id:"02",text:" 基础资料 ",href:"javascript:void(0)"});
root.appendChild(obj02);
 
 
  tree=new Ext.tree.TreePanel({
  waitTitle : '请稍候',
     waitMsg : '正在加载......',
renderTo:document.body,
root:root,
width:document.body.scrollWidth,
height:window.screen.availHeight 
});


 
tree.doLayout( );
 
 //接下来,初始化设置
   var frameobj=opener.parent.rightFrame;
             var selectRows = frameobj.grid.getSelectionModel().getSelections();
             var roleid=selectRows[0].get('roleid');
              
             var olddata=getSysRoleLimitsList(roleid);//数据库得到的数据
       
             olddata=eval("["+olddata+"]");
             
          
            changeAllChild(root);//这样,所在结点都会被加载
           removeAllcheckchange(root);
            for(var j=0;j<olddata.length;j++)
              
               {
          
            var lastobj=eval("obj"+olddata[j][0]+"$"+olddata[j][1]);
            
          
            var check;
            if(olddata[j][2]=='0')
            {
            check=false;
            }
            else
            {
            check=true;
            }
           
            //lastobj.getUI().toggleCheck(check);
            lastobj.getUI().checkbox.checked=check;
            changeAllParent(lastobj);
            
          
          
               }
           addAllcheckchange(root);


});

 类似资料:

相关阅读

相关文章

相关问答