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

jquery tree使用json数据格式的前后台交互,json能获得,可是前台不显示树??在线等帮助。。
后台:public partial class AppmangeMent : System.Web.UI.Page
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  GetJson();
  }
  }

  public static bool IsHaveChild(int id)
  {  
  bool flag = false;
  string Hql = "from Frm_ModuleInfo where PARENTID=" + id + "";
  Frm_ModuleBLL bll = new Frm_ModuleBLL();
  IList<Frm_ModuleInfo> lst = bll.GetAllDemos(Hql);
  if (lst.Count > 0)
  {
  flag = true;
  }
  return flag;
  }
  public static IList<Frm_ModuleInfo> GetChild(int id)
  {
  Frm_ModuleBLL bll = new Frm_ModuleBLL();
   
  string Hql = "from Frm_ModuleInfo where PARENTID=" + id + "";
  IList<Frm_ModuleInfo> lst = bll.GetAllDemos(Hql);
  return lst;
  }
   

  [WebMethod]
  public static string GetJson()
  {
  string json = "[";
  IList<Frm_ModuleInfo> t = ReturnParentTree();
  foreach (Frm_ModuleInfo model in t)
  {
  if (model != t[t.Count - 1])
  {
  json += GetJsonByModel(model) + ",";
  }
  else
  {
  json += GetJsonByModel(model);
  }
  }
  json += "]";
  json = json.Replace("'", "\"");
  return json;
  }
  public static string GetJsonByModel(Frm_ModuleInfo t)
  {
  string json = "";
  bool flag = IsHaveChild(t.MODULEID);
  json = "{"
  + "'id':'" + t.MODULEID + "',"
  + "'text':'" + t.MODULENAME + "',"
  + "'value':'" + t.MODULEID + "',"
  + "'showcheck':true,"
  + "'checkstate':'0',"
  + "'hasChildren':" + flag.ToString().ToLower() + ","
  + "'isexpand':false,"
  + "'ChildNodes':"; 
  if (!flag)
  {
  json += "null,";
  json += "'complete':false}";
  }
  else
  {
  json += "[";
  IList<Frm_ModuleInfo> list = GetChild(t.MODULEID);
  foreach (Frm_ModuleInfo tree in list)
  {
  if (tree != list[list.Count - 1])
  {
  json += GetJsonByModel(tree) + ",";
  }
  else
  {
  json += GetJsonByModel(tree);
  }
  }
  json += "],'complete':true}";
  }
  return json;
  } 


  public static IList<Frm_ModuleInfo> ReturnParentTree()
  {
  Frm_ModuleBLL bll = new Frm_ModuleBLL();
  string Hql = "from Frm_ModuleInfo whe