一直想整下,老是忘记
dtree的下载和事例 http://www.open-open.com/ajax/ajax20080721113203.htm
-------------------------------------------js部分------------------------------------------------------
<script src="js/jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript" src="../dtree/dtree.js"></script>
<link type="text/css" href="../dtree/dtree.css" rel="Stylesheet" />
<script type="text/javascript">
$(function(){
d=new dTree('d');
var inhtml="";
$.getJSON(
"do/GetJcdw.ashx?"+Math.random(),
function(data) {
$.each(data, function(k, v) {
var ddwid=data[k].dwid;
var dpid=data[k].pid;
var ddwname=data[k].dwname;
var bz=data[k].bz;
d.add(ddwid,dpid,ddwname,"javascript:clickfun('"+ddwid+"','"+dpid+"','"+ddwname+"','"+bz+"')");
});
document.getElementById("divtree").innerHTML=d;
}
);
})
-----------------------------------------------------html部分-------------------------------------
<div class="dtree">
<p>
<a href="javascript: d.openAll();">打开所有</a> | <a
href="javascript: d.closeAll();">关闭所有</a></p>
<div id="divtree">
</div>
</div>
----------------------------------------------------无限级部分-----------------------------------
-----------GetJcdw.ashx一般处理处理程序,返回json代码
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string parenetid = "0";
string tes = GetTrees(parenetid);
string flag = " {\"dwid\":\"0\",\"pid\":\"-1\",\"dwname\":\"点位类型\"} ";
string result = "";
if (tes == "")
{
result = "[" + flag + "]";
}
else
{
result = "[" + flag + "," + tes.Substring(0, tes.Length - 1) + "]";
}
context.Response.Write(result);
}
string tress = "";
/// <summary>
/// 返回树的字符串
/// </summary>
/// <returns></returns>
public string GetTrees(string parentid)
{
//无限级数据库可以为1个表中的主id和关联id关联
//id name 关联id
// 1 name 1 0
// 2 name2 1
// 3 name 3 1
//1为2,3 id的上一级id
System.Data.DataSet ds = GetListByParents(parentid);
if (ds != null)
{
System.Data.DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
string ptid = dt.Rows[i]["parentid"].ToString();
string did = dt.Rows[i]["dwid"].ToString();
if (jcdwbll.ExitNodes(did, cityid))
{
tress += "{ \"dwid\":\"" + did + "\",\"pid\":\"" + parentid + "\",\"dwname\":\"" + dt.Rows[i]["DWNAME"] + "\",\"bz\":\"" + dt.Rows[i]["bz"] + "\"},";
GetTrees(did);
}
}
}
}
return tress;
}
-----------前台js,html和ajax的ashx大概代码----记录下