JimmyJin
走在架构师的大道上,学习的乐趣就在于将知识应用于具体实践中,在实战中实现知识的价值。
posts - 4,comments - 0,trackbacks - 0

public class TProjectSub 
{ private String id;// 项目子项id
 private String project;// 业务流水号
 private String projectSubName;// 子项目名称
 private String projectCode;//项目编号
...
}
ViewAction.class
public ActionForward execute(ActionMapping actionMapping,
   ActionForm actionForm, HttpServletRequest request,
   HttpServletResponse response) throws Exception {
... 
request.setAttribute("projects", subProjects);
}
<script type="text/javascript">
   
function subproject(id,pid,name,code){
 this.id=id;
 this.pid=pid;
 this.name=name;
 this.projectCode=code;
 
}

subproject.prototype.toString=function(){
 alert("name===>"+this.name+" id===>"+this.id+"  pid=>"+this.pid);

var demo=new Array();
  
<c:forEach var="item" items="${projects}">
 var project=new subproject
  (
   '<c:out value="${item.id}"/>',
   '<c:out value="${item.project}"/>',
   '<c:out value="${item.projectSubName}"/>',
   '<c:out value="${item.projectCode}"/>'
  );
 demo.push(project);
</c:forEach>

var res="";
function treeNode(array,bean,tree,code){
 var codeId=code;
//  var a =new WebFXTreeItem(bean.name,"javaScript:showDiv(this,"+"'"+bean.id+"','"+bean.pid+"');");
for(var j=0;j<array.length;j++){
  var sub=demo[j];
// var b =new WebFXTreeItem(sub.name,"javaScript:showDiv(this"+",'"+sub.id+"','"+sub.pid+"');");
  if(sub.pid==bean.id){
   var b ="var b"+sub.id+"=new WebFXTreeItem('"+sub.name+"',";
     b+="\"";
     b+="javaScript:showDiv(this,";
     b+="'"+sub.id+"',";
     b+="'"+sub.pid+"');\");";
   
   if(sub.pid=='<c:out value="${topTreeId}"/>'){
    res+=b;
    res+="tree.add(b"+sub.id+");";
    codeId="b"+sub.id;
   }else{

   if(res.indexOf(codeId)<0){
    var a ="var "+codeId+"=new WebFXTreeItem('"+bean.name+"',";
     a+="\"";
     a+="javaScript:showDiv(this,";
     a+="'"+bean.id+"',";
     a+=""+bean.pid+"');\");";
     res+=a;
    }

   var b ="var a"+sub.id+"=new WebFXTreeItem('"+sub.name+"',";
     b+="\"";
     b+="javaScript:showDiv(this,";
     b+="'"+sub.id+"',";
     b+="'"+sub.pid+"');\");"; 
     res+=b;

  if(res.indexOf(("a"+sub.pid))>-1){
   codeId="a"+sub.pid;
  }
     res+=""+codeId+".add(a"+sub.id+");";
     if(sub.pid!=codeId.substr(1,codeId.length)){
      codeId="a"+sub.id;
     }
   }
   treeNode(array,sub,tree,codeId);
  } 
 }  
   return res;
}

 


if (document.getElementById) {
 var tree = new WebFXTree('<c:out value="${topTreeName}"/>',"javaScript:showDiv(this,'<c:out value="${topTreeId}"/>','-1','');");
 tree.setBehavior('classic');
  var bean=new subproject
   (
    '<c:out value="${topTreeId}"/>',
    '-1',
    '<c:out value="${topTreeName}"/>'
   );
 eval(treeNode(demo,bean,tree,""));


//实际
 document.write(tree);
}
 

var ID,parentID,projectCode,temp;

function addCallBack(data)//data是后台返回的值,名字自取,也可省略,因为JS允许
   {
     if(data>0){
   alert("子项目分解成功 "); //处理方法……;如果callBack()没有写明返回值,可以通过argments[0]拿到
   tree.getSelected().add(new WebFXTreeItem(dwr.util.getValue("projectSubName"),"javaScript:showDiv(this,"+"'"+ID+"','"+parentID+"','"+projectCode+"');"));
      closeDiv();
      tree.getSelected().expand(); 
 }else{
      alert("子项目分解失败");
 }
  
   }

 function editCallBack(data){
 //处理方法……;如果callBack()没有写明返回值,可以通过argments[0]拿到
 if(data>0){
  alert("项目修改成功");
  document.getElementById(tree.getSelected().id+"-anchor").innerHTML=dwr.util.getValue("projectSubName");
    closeDiv();
 
 }else{
 alert("项目修改失败");
 }
 }

function delCallBack(data){

 if(data>0){
  alert("有子节点,不允许删除"); 
 }else{
  alert("删除成功");
  if (tree.getSelected()) {
   tree.getSelected().remove();
   closeDiv();
   }
 };
}

function addNode() {
var pname=dwr.util.getValue("projectSubName");
alert(pname);

 if (tree.getSelected()) {
  var level;
  if(tree.getSelected().text=='<c:out value="${topTreeName}"/>'){
    level=1;
    projectCode="none";
     }else{
     level=tree.getSelected()._level+1;
   }
 var totalChildren=tree.getSelected().childNodes.length;
 
 if(totalChildren>=1){  
  var sAction=tree.getSelected().childNodes[totalChildren - 2].action;
  projectCode=sAction.substr(24,20);
 }  
   
  if(level>=3){
   alert("最多只能分为3个层级");
  }else{ 
   alert("ID"+ID);
        // alert("parentID=>"+ID+" projectCode=>"+projectCode+" level"+level);
     zdxmfjDeal.doAdd(pname,ID,projectCode,level,addCallBack); 
     }
 }
}

function editNode() {
 if (tree.getSelected()) {
     zdxmfjDeal.doEdit(ID,dwr.util.getValue("projectSubName"),editCallBack);//回调函数callBack()
  }
}

function delNode() {
zdxmfjDeal.doDelChild(ID,delCallBack);
}


function showDiv(obj,id,pid,code) {
 ID=id;
 parentID=pid;
 projectCode=code;
 // alert(id+ " parentID" +pid+"projectCode"+code)
 document.all.inputNameDiv.style.display="";
 document.all.projectSubName.value="";
 document.all.inputNameDiv.style.top=document.getElementById(tree.getSelected().id+"-anchor").offsetTop+15;
 document.all.inputNameDiv.style.left=document.getElementById(tree.getSelected().id+"-anchor").offsetLeft;

}
function closeDiv() {
 document.all.inputNameDiv.style.display="none";
}

</script>

posted on 2009-09-04 10:22 jimmy2009 阅读(507) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: