您的位置:首页 > 其它

三级联动下拉框

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

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: