dwr tree加载页面的写法

动态树的页面加载  用dwr加载

常常有两个字段,一棵树还需要挂树
后台处理     根节点+第一级+子级
              可以写死 +字段PID=0+  pid=第一级的uuid 
          要挂树就用pid等于uuid进行判断





记得加载
ext-tree.js 头文件
cmLeafPosition.initTree=function(){
	var root = new Ext.tree.AsyncTreeNode({
                id : "root",
                leaf : false,
                text : "烟叶类型",
                href:'#',
                hrefTarget:''  
            });
     var loader = new Ext.tree.DWRTreeLoader({    
                   dwrCall:cmLeafTypeManager.getNodes  
               });
  var tree=cmLeafPosition.baseTree=new Ext.tree.TreePanel({
   id:'tree',
   root:root,
   loader:loader,
   useArrows:true,//是否使用箭头样式
   autoScroll:true,
   animate:true,//展开,收缩动画
   rootVisble:true//根节点是否可见
   //enableDD:true, //  是否可以拖放节点
    });
//tree的点击事件
Ext.getCmp('tree').on('click',function(Nodes,e){
  var NodeText=cmLeafPosition.NodeText=Nodes.text;//获取点击的值
  var id=cmLeafPosition.id=Nodes.id;//获取ID
  })




后台处理

public List getTreeNodes(String id, String href, String hrefTarget) {
		List nodes = new ArrayList();
		List children = new ArrayList();
		if (id.equalsIgnoreCase("root")) {
			children = dao.getAllObjectLevel();
		} else {
			children = dao.getAllChildrenObjectLevel(id);
		}
		for (Iterator iterator = children.iterator(); iterator.hasNext();) {
			CmMaterialCategory cmMaterialCategory = (CmMaterialCategory) iterator.next();
			boolean isEnd = cmMaterialCategory.getMaterialCategoryLevel().equalsIgnoreCase("2");
			Integer cmMaterialCategoryLevel=new Integer(cmMaterialCategory.getMaterialCategoryLevel());
			nodes.add(new TreeNode(cmMaterialCategory.getMaterialCategoryId(),
					cmMaterialCategory.getMaterialCategoryName(),
					cmMaterialCategory.getMaterialCategoryCd(), "con-org",href, hrefTarget, false, isEnd,
					cmMaterialCategoryLevel==null?new Integer(0):cmMaterialCategoryLevel ));
		}
		return nodes;
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.icsshs.tlcom.cm.material.service.CmMaterialCategoryManager#
	 * getParentTreeNodes(java.lang.String, java.lang.String, java.lang.String)
	 */
	public List getParentTreeNodes(String id, String href, String hrefTarget) {
		List nodes = new ArrayList();
		List children = new ArrayList();
		if (id.equalsIgnoreCase("root")) {
			children = dao.getAllObjectLevel();
		}
		for (Iterator iterator = children.iterator(); iterator.hasNext();) {
			CmMaterialCategory cmMaterialCategory = (CmMaterialCategory) iterator.next();
			Integer cmMaterialCategoryLevel=new Integer(cmMaterialCategory.getMaterialCategoryLevel());
			nodes.add(new TreeNode(cmMaterialCategory.getMaterialCategoryId(),
					cmMaterialCategory.getMaterialCategoryName(),
					cmMaterialCategory.getMaterialCategoryCd(), "con-org",href, hrefTarget, false, true,
					cmMaterialCategoryLevel==null?new Integer(0):cmMaterialCategoryLevel));
		}
		return nodes;
	}


你可能感兴趣的:(java,DAO,DWR,ext)