这个JS数是对AJAX TreeView 里的进一步修改,可以 继承 Sbqcel_Tree   ,该类的构造函数需要显示树HTML的父节点的ID传进来,这里最好让树的实例名和父节点ID一致,因为有些事件方法需要用树实例去调用.
在继承类里需要注意的是:
1). 必须指定AJAX调用的地址:
2).必须实现方法 openNode  ,在这个方法里必须调用方法 openCloseNode
3).必须实现方法 getHtmlData , 在这个方法里必须调用方法 appendHtml
getHtmlData 是对AJAX获取到的数据进行处理,因为不同的需求获取到的是树HTML数据不一样
获取到数据后可能还用调用其它方法进行一些处理,所以对 openNode 单独实现

2008-03-06更新:修复一个页面只能有一个Tree实例的BUG,修改删除节点实现方式,新增更新结点方法(给出使用Json示例)

有几个方法是要用到的:

String.prototype.Replace = function(oldValue,newValue) 

    
return this.replace(new RegExp(oldValue,"gi"), newValue); 
}
String.prototype.Trim 
= function()
{
    
return this.replace(/(^\s*)|(\s*$)/g, "");
}

function getObjById(id)
{   
    
if (typeof(id) != "string" || id == ""return null;
    
if (document.getElementById) return document.getElementById(id);
    
if (document.all) return document.all(id);            
    
try {return eval(id);} catch(e){ return null;}
}
Sbqcel_Tree 类的代码如下 :
Sbqcel_Tree

可下载示例 下载Demo
在示例里将要调用的方法和方法所在的类名传递回服务器,在服务器端通过反射执行相关的方法:
using System;
using System.Web;
using System.Reflection;

/// <summary>
/// AjaxUtil 的摘要说明
/// </summary>
public class AjaxUtil
{
    
private HttpContext httpContext;
    
public AjaxUtil( HttpContext httpContext )
    {
        
this.httpContext = httpContext;
    }

    
public object callMethod( string className,string methodName )
    {
        Type type 
= Type.GetType( className );
        
object dObj = Activator.CreateInstance( type , new object[ ] { httpContext } );
        MethodInfo method 
= type.GetMethod( methodName );
        
return method.Invoke( dObj , null );
    }
}
posted on 2007-08-05 19:56  空空儿  阅读(4020)  评论(0编辑  收藏  举报