问题描述
<scriptlanguage="javascript">varconfig={id:"tg1",width:"800",renderTo:"div1",headerAlign:"left",headerHeight:"30",dataAlign:"left",indentation:"20",folderOpenIcon:"images/folderOpen.gif",folderCloseIcon:"images/folderClose.gif",defaultLeafIcon:"images/defaultLeaf.gif",hoverRowBackground:"false",folderColumnIndex:"1",itemClick:"itemClickEvent",columns:[{headerText:"",headerAlign:"center",dataAlign:"center",width:"20",handler:"customCheckBox"},{headerText:"名称",dataField:"name",headerAlign:"center",handler:"customOrgName"},{headerText:"拼音码",dataField:"code",headerAlign:"center",dataAlign:"center",width:"100"},{headerText:"负责人",dataField:"assignee",headerAlign:"center",dataAlign:"center",width:"100"}],//data:'treegrid_data2.json'data:[{name:"城区分公司",code:"CQ",assignee:"",children:[{name:"城区卡品分销中心"},{name:"先锋服务厅",children:[{name:"chlid1"},{name:"chlid2"},{name:"chlid3",children:[{name:"chlid3-1"},{name:"chlid3-2"},{name:"chlid3-3"},{name:"chlid3-4"}]}]},{name:"半环服务厅"}]},{name:"清新分公司",code:"QX",assignee:"",children:[]},{name:"英德分公司",code:"YD",assignee:"",children:[]},{name:"佛冈分公司",code:"FG",assignee:"",children:[]}]};这里面的data是写的固定值,我想从数据库中取,怎么写?
解决方案
解决方案二:
//data:'treegrid_data2.json'这句就是动态绑定数据啊。然后你在这个json里写查询方法:BLL.bllView_EnquiryVendorbll=newBLL.bllView_EnquiryVendor();List<Model.modelView_EnquiryVendor>dataList=bll.GetModelList(strWhere,GetPageSize(),GetPageIndex());Hashtableht=newHashtable();ht.Add("rows",dataList);ht.Add("total",bll.GetRecordCount(strWhere));//序列化JavaScriptSerializerserializer=newJavaScriptSerializer();stringjsonList=serializer.Serialize(ht);Response.Clear();Response.Write(jsonList);Response.Flush();Response.End();
解决方案三:
或者直接用url:'<%=ResolveClientUrl("~/xxx/datajson.aspx")%>',在datajson中:BLL.bllView_EnquiryVendorbll=newBLL.bllView_EnquiryVendor();List<Model.modelView_EnquiryVendor>dataList=bll.GetModelList(strWhere,GetPageSize(),GetPageIndex());Hashtableht=newHashtable();ht.Add("rows",dataList);ht.Add("total",bll.GetRecordCount(strWhere));//序列化JavaScriptSerializerserializer=newJavaScriptSerializer();stringjsonList=serializer.Serialize(ht);Response.Clear();Response.Write(jsonList);Response.Flush();Response.End();
解决方案四:
引用1楼zyl_leilei的回复:
//data:'treegrid_data2.json'这句就是动态绑定数据啊。然后你在这个json里写查询方法:BLL.bllView_EnquiryVendorbll=newBLL.bllView_EnquiryVendor();List<Model.modelView_EnquiryVendor>dataList=bll.GetModelList(strWhere,GetPageSize(),GetPageIndex());Hashtableht=newHashtable();ht.Add("rows",dataList);ht.Add("total",bll.GetRecordCount(strWhere));//序列化JavaScriptSerializerserializer=newJavaScriptSerializer();stringjsonList=serializer.Serialize(ht);Response.Clear();Response.Write(jsonList);Response.Flush();Response.End();
直接写url页面加载汇报错。
解决方案五:
我现在的treegrid_data2.json这个里面写的是已经获取到的json数据,但是页面上加载不出来引用1楼zyl_leilei的回复:
//data:'treegrid_data2.json'这句就是动态绑定数据啊。然后你在这个json里写查询方法:BLL.bllView_EnquiryVendorbll=newBLL.bllView_EnquiryVendor();List<Model.modelView_EnquiryVendor>dataList=bll.GetModelList(strWhere,GetPageSize(),GetPageIndex());Hashtableht=newHashtable();ht.Add("rows",dataList);ht.Add("total",bll.GetRecordCount(strWhere));//序列化JavaScriptSerializerserializer=newJavaScriptSerializer();stringjsonList=serializer.Serialize(ht);Response.Clear();Response.Write(jsonList);Response.Flush();Response.End();
解决方案六:
能方便加一下您的qq吗?我的是260353773.谢谢啦引用2楼zyl_leilei的回复:
或者直接用url:'<%=ResolveClientUrl("~/xxx/datajson.aspx")%>',在datajson中:BLL.bllView_EnquiryVendorbll=newBLL.bllView_EnquiryVendor();List<Model.modelView_EnquiryVendor>dataList=bll.GetModelList(strWhere,GetPageSize(),GetPageIndex());Hashtableht=newHashtable();ht.Add("rows",dataList);ht.Add("total",bll.GetRecordCount(strWhere));//序列化JavaScriptSerializerserializer=newJavaScriptSerializer();stringjsonList=serializer.Serialize(ht);Response.Clear();Response.Write(jsonList);Response.Flush();Response.End();
解决方案七:
引用4楼bitstrong30的回复:
我现在的treegrid_data2.json这个里面写的是已经获取到的json数据,但是页面上加载不出来Quote: 引用1楼zyl_leilei的回复:
//data:'treegrid_data2.json'这句就是动态绑定数据啊。然后你在这个json里写查询方法:BLL.bllView_EnquiryVendorbll=newBLL.bllView_EnquiryVendor();List<Model.modelView_EnquiryVendor>dataList=bll.GetModelList(strWhere,GetPageSize(),GetPageIndex());Hashtableht=newHashtable();ht.Add("rows",dataList);ht.Add("total",bll.GetRecordCount(strWhere));//序列化JavaScriptSerializerserializer=newJavaScriptSerializer();stringjsonList=serializer.Serialize(ht);Response.Clear();Response.Write(jsonList);Response.Flush();Response.End();
你的代码贴出来看看?
解决方案八:
引用5楼bitstrong30的回复:
能方便加一下您的qq吗?我的是260353773.谢谢啦Quote: 引用2楼zyl_leilei的回复:
或者直接用url:'<%=ResolveClientUrl("~/xxx/datajson.aspx")%>',在datajson中:BLL.bllView_EnquiryVendorbll=newBLL.bllView_EnquiryVendor();List<Model.modelView_EnquiryVendor>dataList=bll.GetModelList(strWhere,GetPageSize(),GetPageIndex());Hashtableht=newHashtable();ht.Add("rows",dataList);ht.Add("total",bll.GetRecordCount(strWhere));//序列化JavaScriptSerializerserializer=newJavaScriptSerializer();stringjsonList=serializer.Serialize(ht);Response.Clear();Response.Write(jsonList);Response.Flush();Response.End();
解决方案九:
你把name和code分别改成id,text,tree只认这个。
解决方案十:
引用8楼zyl_leilei的回复:
你把name和code分别改成id,text,tree只认这个。
也不行,数据加载不上来
解决方案十一:
引用9楼bitstrong30的回复:
Quote: 引用8楼zyl_leilei的回复:
你把name和code分别改成id,text,tree只认这个。也不行,数据加载不上来
不好意思,treegrid没有用过,好像这个字段名称不影响。不过你的json格式就不正确吧,你先照这个例子试试:<tableid="tt"style="width:600px;height:400px"></table>$('#tt').treegrid({url:'treegrid_data2.json',idField:'code',treeField:'name',columns:[[{title:'name',field:'name',width:180},{field:'code',title:'code',width:60},{field:'assignee',title:'assignee',width:80}]]});json里面先简单的数据试试:[{name:"城区分公司",code:"CQ",assignee:"",children:[{name:"城区卡品分销中心",code:"",assignee:""},{name:"先锋服务厅",code:"",assignee:""}]}
解决方案十二:
不行,试了好多方法。头疼引用10楼zyl_leilei的回复:
Quote: 引用9楼bitstrong30的回复:
Quote: 引用8楼zyl_leilei的回复:
你把name和code分别改成id,text,tree只认这个。也不行,数据加载不上来
不好意思,treegrid没有用过,好像这个字段名称不影响。不过你的json格式就不正确吧,你先照这个例子试试:<tableid="tt"style="width:600px;height:400px"></table>$('#tt').treegrid({url:'treegrid_data2.json',idField:'code',treeField:'name',columns:[[{title:'name',field:'name',width:180},{field:'code',title:'code',width:60},{field:'assignee',title:'assignee',width:80}]]});json里面先简单的数据试试:[{name:"城区分公司",code:"CQ",assignee:"",children:[{name:"城区卡品分销中心",code:"",assignee:""},{name:"先锋服务厅",code:"",assignee:""}]}