困扰了我近两个星期的拖拽树

swigun 2009-06-11
本人初学java,又刚刚接触E3树,准备开发一个拖拽树看了E3的实例,E3开发指南,搞了近两个星期,刚刚有点希望又一筹莫展了。具体问题如下:按照样例结合自己的项目开发拖拽树时,在jsp页面捕捉不到点击树节点和拖动树节点的事件,因此无法继续。页面中的如下函数执行不到
//当节点对象和树对象构造完了、执行render之前,会调用该方法
//所以可以在这做函数注册处理.
function treeRenderBeforeHandler(pTree){
    pTree.on('beforerender', function(pTree){
   // pTree.setTitle("请选择节点!:d"); 
    });

    pTree.on('click', function(node){
    alert(" 进入click");
     pTree.setTitle("当前节点:" + node.text);
    }); 
   
    pTree.on('movenode',function(pTree,pNode, pOldParent, pNewParent, pIndex){
      //修改父亲机构ID
      pNode.attributes.newParentOrgID = pNewParent.attributes.orgID;
    });

}




Action代码:

public void parentsTree(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DetachedCriteria detachedCriteria = DetachedCriteria
.forClass(JcataLog.class);
List nodeList = commonDAO.findByCriteria(detachedCriteria);
UserDataUncoder menuUncoder = new UserDataUncoder(){
// 获取当前节点编号
public Object getID(Object menuData) throws UncodeException {
JcataLog domain = (JcataLog)menuData;
return domain.getId();
}
// 获取父亲节点编号
public Object getParentID(Object menuData) throws UncodeException {
JcataLog domain = (JcataLog)menuData;
if(domain.getId()==(long)1) return null;
else
return domain.getJcataLog().getId();
}
};

// Tree模型构造器,用于生成树模型
AbstractWebTreeModelCreator treeModelCreator = new
AbstractWebTreeModelCreator(){
// 该方法负责将业务数据映射到树型节点
protected Node createNode(Object menuData, UserDataUncoder uncoder)
{
JcataLog domain = (JcataLog)menuData;
WebTreeNode result = new WebTreeNode(domain.getName(),"org"+domain.getId());
result.setDragable(true);//允许拖
result.setDropable(true);//允许放
// 注意:以下三个属性的Key 和JS 函数中对应喔
result.setAttribute("orgID", domain.getId().toString());//记本身ID,和父ID
if(domain.getId()!=(long)1){
result.setAttribute("oldParentOrgID", domain.getJcataLog().getId().toString());
result.setAttribute("newParentOrgID", domain.getJcataLog().getId().toString());}
return result;
}
};
treeModelCreator.init(request);
TreeModel treeModel = treeModelCreator.create(nodeList, menuUncoder);
TreeDirector director = new DefaultTreeDirector();
// director.setComparator(new ReverseComparator(new AbstractNodeComparator()
// {
// protected Comparable getComparableProperty(Node pNode) {
// JcataLog org = (JcataLog)pNode.getUserData();
// return  org.getName();
// }
//
// }
//
// ));
ExtTreeBuilder treeBuilder = new ExtTreeBuilder ();
treeBuilder.init(request);
treeBuilder.setTitle("拖动节点看看");
director.build(treeModel, treeBuilder);
String treeScript = treeBuilder.getTreeScript();
System.out.println("============================================================================");
System.out.println(treeScript);
System.out.println("============================================================================");
request.setAttribute("treeScript", treeScript);
request.getRequestDispatcher("/module/module_left.jsp").forward(request,response);}



后来将其中的treeScript打印出来:

if ( typeof(E3TreeExtReadyHandler) == 'function' )
  E3TreeExtReadyHandler(tree, 'tree');
tree.render();
root.expand();
});
</script>

================================
与E3示例中相比

if ( typeof(E3TreeExtReadyHandler) == 'function' )
  E3TreeExtReadyHandler(tree, 'tree');
if ( typeof(treeRenderBeforeHandler) == 'function' )
  treeRenderBeforeHandler(tree);
tree.render('tree');
root.expand();
if ( typeof(treeRenderAfterHandler) == 'function' )
  treeRenderAfterHandler(tree);
});
</script>


少了中间红色的部分,而那些就是那个函数,不知道怎么搞了





huangyh 2009-06-12
是不是e3 版本不对
huangyh 2009-06-12
用圈子里最新版本吧
Global site tag (gtag.js) - Google Analytics