首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

jquery tree使用json数据格式的前后台交互,json能获得,可是前台不显示树?帮助。

2012-08-13 
jquery tree使用json数据格式的前后台交互,json能获得,可是前台不显示树??在线等帮助。。后台:public partia

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 where PARENTID=0 order by MODULECODE asc";
  IList<Frm_ModuleInfo> lst = bll.GetAllDemos(Hql);


  return lst;
  }


  }

前台: <script type="text/javascript">
  $(document).ready(function () {
  $.ajax({
  type: "post",
  contentType: "application/json;charset=utf-8",
  dataType: "json",
  url: "AppMangeMent.aspx/GetJson",
  success: function (data) {
  var o = { showcheck: true };
  o.data = eval(data.d);
  $("#showTree").treeview(o);
  }
  });
  });</script> 





[解决办法]
严格的json格式 用 双引号


比如

{"name": "Tom"}

[解决办法]
如果预期应该显示树的地方什么都没有,那有可能是js在执行过程中报错了。你打开firebug看看有没有js错误。

热点排行