三级联动下拉框

之前一直用别人写的三级联动,看起来很不舒服,这两天自己写了一个,后台传送,前台分解

  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);
        }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值