日期:2014-05-16  浏览次数:20424 次

estJS动态生成树问题求助

我要实现的功能是 

 左边是一个树结构,右边是一个页面,根据点击左侧树的节点(包括子结点和叶子),向右侧页面传递一个参数id ,后台根据id在右边页面显示数据。

小弟不知道节点事件和参数传递在哪里加?请大神指点!


部分代码如下:
js文件
Ext.onReady(function() {
  Ext.BLANK_IMAGE_URL = "Extjs3.2.0/resources/images/default/s.gif";
  var Tree = Ext.tree;
  var tree = new Tree.TreePanel({
  el: 'west_content', //渲染到
  useArrows: true,
  autoHeight: true,
  split: true,
  lines: true,
  autoScroll: true,
  animate: true,
  enableDD: true,
  border: false,
  containerScroll: true,
  loader: new Tree.TreeLoader({
  dataUrl: 'ServletHandlers/GetTrees.ashx'
  })
  });
  var root = new Tree.AsyncTreeNode({
  text: 'ICD10-疾病编码',
  draggable: true,
  id: '0'
  });
  tree.setRootNode(root);
  tree.render();
  // root.expand();


后台动态生成的树

  public void ProcessRequest(HttpContext context)
  {
  string strSql = "select ID,ParentID,KindName from EMR_ICD10KIND";
  dbOperator db = new dbOperator();
  DataTable dt = db.Execute(strSql);
  string strResult = "[";
  if (dt.Rows.Count > 0)
  {
  DataRow[] dr = dt.Select("ParentID='1'");
  strResult = DtTreeToJson(dt, strResult, dr);
  }
  strResult += "]";
  context.Response.ContentType = "text/plain";
  context.Response.Write(strResult.ToString());
  context.Response.End();
  }

  private static string DtTreeToJson(DataTable dt, string strResult, DataRow[] dr)
  {
  if (dr.Length > 0)
  {
  for (int i = 0; i < dr.Length; i++)
  {

  strResult += "{";
  strResult += "text:'" + dr[i]["KindName"] + "',";
  strResult += "id:'" + dr[i]["ID"] + "',";
  DataRow[] drChild = dt.Select("ParentId='" + dr[i]["ID"] + "'");
  if (drChild.Length > 0)
  {
  string id = string.Empty;
  strResult += "leaf:false,";
  // strResult += "listeners:{\"click\":function(node,event){alert(node.text) ;"++"}},";
  // strResult += "href:'toDiseaseDetail.aspx?ID="++"',";
  strResult += "href:'toDiseaseDetail.aspx',";
  strResult += "hrefTarget:'main',";
  // strResult += " listeners: { \"click\": function(node, e){ alert(node.id) } }";
  strResult += "children:[";
  strResult = DtTreeToJson(dt, strResult, drChild);
  strResult += "]";
  }
  else
  {
  strResult += "href:'toDiseaseDetail.aspx',";<