三级联动下拉框
2017-12-07 13:42
99 查看
之前一直用别人写的三级联动,看起来很不舒服,这两天自己写了一个,后台传送,前台分解
SelectChanged:function(type,data)
{
debugger;
var ZRFSelect='';
var QuestionSelect='';
var ReasonSelect='';
var ZRFTid='';
var QusTid='';
if(type=='ZRF')
{
QuestionSelect +='<option value='+'-1'+'>请选择</option>'
ReasonSelect +='<option value='+'-1'+'>请选择</option>'
$("#Reason").empty();
$("#Reason").append(ReasonSelect);
if(_Framework.dataModel.ResponsCol.LMS.length!=0)
{
for(var i=0;i<_Framework.dataModel.ResponsCol.LMS.length;i++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].FieldValue==data)
{
ZRFTid=_Framework.dataModel.ResponsCol.LMS[i].Tid;
for(var q=0;q<_Framework.dataModel.ResponsCol.LMS[i].LMS.length;q++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FKUpperTid==ZRFTid)
{
QuestionSelect+='<option value='+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FieldValue+'>'+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FieldName+'</option>'
}
}
}
}
}
$("#WT").empty();
$("#WT").append(QuestionSelect);
}
if(type=='Qus')
{
ReasonSelect +='<option value='+'-1'+'>请选择</option>'
var zrf_val=$("#ZRF").val();
var Que_val=$("#WT").val();
var zrf_tid=null;
var Que_tid=null;
if(_Framework.dataModel.ResponsCol.LMS.length!=0)
{
for(var i=0;i<_Framework.dataModel.ResponsCol.LMS.length;i++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].FieldValue==zrf_val)
{
zrf_tid=_Framework.dataModel.ResponsCol.LMS[i].Tid;
for(var q=0;q<_Framework.dataModel.ResponsCol.LMS[i].LMS.length;q++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FKUpperTid==zrf_tid && _Framework.dataModel.ResponsCol.LMS[i].LMS[q].FieldValue==Que_val)
{
for(var r=0;r<_Framework.dataModel.ResponsCol.LMS[i].LMS[q].LMS.length;r++)
{
ReasonSelect+='<option value='+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].LMS[r].FieldValue+'>'+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].LMS[r].FieldName+'</option>'
}
}
}
}
}
debugger;
}
$("#Reason").empty();
$("#Reason").append(ReasonSelect);
}
}
SelectChanged:function(type,data)
{
debugger;
var ZRFSelect='';
var QuestionSelect='';
var ReasonSelect='';
var ZRFTid='';
var QusTid='';
主要是后台返回的JSON
JSON是采用 [{一级,二级(所有二级),三级(所有三级)},{}]这样的层级给出
后台方法
public void GetSelect( string type,out string Res)
{
Responbility LD = new Responbility();
LD.LMS = new List<DBEntity>();
int zrfnum = 0;
//获取责任方,并赋值
Responbility ResponsibilityResponse = GetDropdownList(type, 0, 0);
if (ResponsibilityResponse != null && ResponsibilityResponse.LMS != null && ResponsibilityResponse.LMS.Count > 0)
{
LD.count = ResponsibilityResponse.LMS.Count;
foreach (DBEntity entity in ResponsibilityResponse.LMS)
{
DBEntity entity_zrf = new DBEntity();
entity_zrf.LMS = new List<DBEntity>();
Responbility Question = GetDropdownList(type, 0, Convert.ToInt32(entity.Tid));
entity_zrf.LMS = new List<DBEntity>();
foreach (DBEntity Item in Question.LMS)
{
DBEntity entity_Qus = new DBEntity();
entity_Qus.LMS = new List<DBEntity>();
if (Item.FKUpperTid == entity.Tid)
{
Responbility Reason = GetDropdownList(type, 0, Convert.ToInt32(Item.Tid));
foreach (DBEntity Item_Rea in Reason.LMS)
{
DBEntity entity_Rea = new DBEntity();
entity_Rea.LMS = new List<DBEntity>();
if (Item_Rea.FKUpperTid == Item.Tid)
{
entity_Rea.count = Reason.LMS.Count;
entity_Rea.Tid = Item_Rea.Tid;
entity_Rea.FieldName = Item_Rea.FieldName;
entity_Rea.FieldValue = Item_Rea.FieldValue;
entity_Rea.FKUpperTid = Item.Tid;
entity_Qus.LMS.Add(entity_Rea);
}
}
entity_Qus.count = Question.LMS.Count;
entity_Qus.Tid = Item.Tid;
entity_Qus.FieldName = Item.FieldName;
entity_Qus.FieldValue = Item.FieldValue;
entity_Qus.FKUpperTid = entity.Tid;
entity_zrf.LMS.Add(entity_Qus);
}
}
entity_zrf.count = ResponsibilityResponse.LMS.Count;
entity_zrf.Tid = entity.Tid;
entity_zrf.FieldName = entity.FieldName;
entity_zrf.FieldValue = entity.FieldValue;
entity_zrf.FKUpperTid = entity.FKUpperTid;
LD.LMS.Add(entity_zrf);
}
}
LD.count = zrfnum;
JavaScriptSerializer jss = new JavaScriptSerializer();
Res = jss.Serialize(LD);
}
SelectChanged:function(type,data)
{
debugger;
var ZRFSelect='';
var QuestionSelect='';
var ReasonSelect='';
var ZRFTid='';
var QusTid='';
if(type=='ZRF')
{
QuestionSelect +='<option value='+'-1'+'>请选择</option>'
ReasonSelect +='<option value='+'-1'+'>请选择</option>'
$("#Reason").empty();
$("#Reason").append(ReasonSelect);
if(_Framework.dataModel.ResponsCol.LMS.length!=0)
{
for(var i=0;i<_Framework.dataModel.ResponsCol.LMS.length;i++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].FieldValue==data)
{
ZRFTid=_Framework.dataModel.ResponsCol.LMS[i].Tid;
for(var q=0;q<_Framework.dataModel.ResponsCol.LMS[i].LMS.length;q++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FKUpperTid==ZRFTid)
{
QuestionSelect+='<option value='+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FieldValue+'>'+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FieldName+'</option>'
}
}
}
}
}
$("#WT").empty();
$("#WT").append(QuestionSelect);
}
if(type=='Qus')
{
ReasonSelect +='<option value='+'-1'+'>请选择</option>'
var zrf_val=$("#ZRF").val();
var Que_val=$("#WT").val();
var zrf_tid=null;
var Que_tid=null;
if(_Framework.dataModel.ResponsCol.LMS.length!=0)
{
for(var i=0;i<_Framework.dataModel.ResponsCol.LMS.length;i++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].FieldValue==zrf_val)
{
zrf_tid=_Framework.dataModel.ResponsCol.LMS[i].Tid;
for(var q=0;q<_Framework.dataModel.ResponsCol.LMS[i].LMS.length;q++)
{
if(_Framework.dataModel.ResponsCol.LMS[i].LMS[q].FKUpperTid==zrf_tid && _Framework.dataModel.ResponsCol.LMS[i].LMS[q].FieldValue==Que_val)
{
for(var r=0;r<_Framework.dataModel.ResponsCol.LMS[i].LMS[q].LMS.length;r++)
{
ReasonSelect+='<option value='+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].LMS[r].FieldValue+'>'+_Framework.dataModel.ResponsCol.LMS[i].LMS[q].LMS[r].FieldName+'</option>'
}
}
}
}
}
debugger;
}
$("#Reason").empty();
$("#Reason").append(ReasonSelect);
}
}
SelectChanged:function(type,data)
{
debugger;
var ZRFSelect='';
var QuestionSelect='';
var ReasonSelect='';
var ZRFTid='';
var QusTid='';
主要是后台返回的JSON
JSON是采用 [{一级,二级(所有二级),三级(所有三级)},{}]这样的层级给出
后台方法
public void GetSelect( string type,out string Res)
{
Responbility LD = new Responbility();
LD.LMS = new List<DBEntity>();
int zrfnum = 0;
//获取责任方,并赋值
Responbility ResponsibilityResponse = GetDropdownList(type, 0, 0);
if (ResponsibilityResponse != null && ResponsibilityResponse.LMS != null && ResponsibilityResponse.LMS.Count > 0)
{
LD.count = ResponsibilityResponse.LMS.Count;
foreach (DBEntity entity in ResponsibilityResponse.LMS)
{
DBEntity entity_zrf = new DBEntity();
entity_zrf.LMS = new List<DBEntity>();
Responbility Question = GetDropdownList(type, 0, Convert.ToInt32(entity.Tid));
entity_zrf.LMS = new List<DBEntity>();
foreach (DBEntity Item in Question.LMS)
{
DBEntity entity_Qus = new DBEntity();
entity_Qus.LMS = new List<DBEntity>();
if (Item.FKUpperTid == entity.Tid)
{
Responbility Reason = GetDropdownList(type, 0, Convert.ToInt32(Item.Tid));
foreach (DBEntity Item_Rea in Reason.LMS)
{
DBEntity entity_Rea = new DBEntity();
entity_Rea.LMS = new List<DBEntity>();
if (Item_Rea.FKUpperTid == Item.Tid)
{
entity_Rea.count = Reason.LMS.Count;
entity_Rea.Tid = Item_Rea.Tid;
entity_Rea.FieldName = Item_Rea.FieldName;
entity_Rea.FieldValue = Item_Rea.FieldValue;
entity_Rea.FKUpperTid = Item.Tid;
entity_Qus.LMS.Add(entity_Rea);
}
}
entity_Qus.count = Question.LMS.Count;
entity_Qus.Tid = Item.Tid;
entity_Qus.FieldName = Item.FieldName;
entity_Qus.FieldValue = Item.FieldValue;
entity_Qus.FKUpperTid = entity.Tid;
entity_zrf.LMS.Add(entity_Qus);
}
}
entity_zrf.count = ResponsibilityResponse.LMS.Count;
entity_zrf.Tid = entity.Tid;
entity_zrf.FieldName = entity.FieldName;
entity_zrf.FieldValue = entity.FieldValue;
entity_zrf.FKUpperTid = entity.FKUpperTid;
LD.LMS.Add(entity_zrf);
}
}
LD.count = zrfnum;
JavaScriptSerializer jss = new JavaScriptSerializer();
Res = jss.Serialize(LD);
}
相关文章推荐
- jquery ajax实现下拉框三级无刷新联动,且保存保持选中值状态
- 三级下拉联动代码
- php jquery ajax json 全国省市区三级联动下拉列表 简单实现
- Android实现三级联动下拉框 下拉列表spinner的实例
- jquery+ligerform三级联动下拉框
- 【JS插件】下拉框通用三级联动选择 省市区三级联动选择
- android 下拉弹出框+地区选择三级联动
- 省市区三级联动下拉框菜单javascript版
- MVC 下拉列表三级联动
- 下拉框三级联动
- jquery ajax实现下拉框三级无刷新联动,且保存保持选中值状态
- 跪求jfinal框架做的三级下拉框联动的demo 和数据库连接的
- ASP.NET MVC + Jquery 实现Ajax下拉框数据三级联动
- jquery+html三级联动下拉框
- 三级联动下拉框,获取省市区信息(内附Oracle城市三级联动数据表)
- AJAX部分---对比js做日期的下拉选择 和 ajax做三级联动;
- 用php和ajax写一个省市区的三级联动,实现地区的下拉选择
- Android实现三级联动下拉框下拉列表spinner
- Android实现三级联动下拉框 下拉列表spinner的实例代码