yii2地址多级联动
??? ???? <div>
?? ??? ?查看地區:<select class="region" name="region[]">
?? ??? ??? ?<option value="0" selected>請選擇...</option>
?? ??? ??? ?<?php foreach ($region as $k => $v): ?>
?? ??? ??? ??? ?<option value="<?=$v['id']?>"><?=$v['name']?></option>
?? ??? ??? ?<?php endforeach ?>
?? ??? ?</select>
?? ??? ?</div>
/**
?* 地址多級聯動
?*/
? $(document).on('change','.region',function()
? {
??? var region_id = $(this).val();
??? var obj = $(this);
??? if(region_id != 0)
??? {
????? $.ajax({
??????? type:"POST",
??????? url:"?r=sign/region",
??????? data:{region_id:region_id},
??????? dataType:"json",
??????? success:function(msg)
??????? {
????????? if(msg.length>0)
????????? {
??????????? var html = '<select class="region" name="region[]"><option value="0">請選擇...</option>';
??????????? $.each(msg,function(k,v)
??????????? {
????????????? html += '<option value="'+v.id+'">'+v.name+'</option>';
??????????? })
??????????? html += '</select>';? ?
??????????? obj.nextAll().remove();??????? ?
??????????? obj.after(html);
????????? }
????? }
????? })
??? }
??? else
??? {
????? obj.nextAll().remove();
??? }
? })
?
?
??? public function actionIndex($id)
??? {
??????? $result = Login::find()->where(['id'=>$id])->asArray()->one();
??????? $res = Sign::find()->where(['u_id'=>$id])->asArray()->one();
??????? $in = Integral::find()->where(['id'=>$id])->asArray()->one();
??????? $region = Region::find()->where(['parent_id'=>0])->asArray()->all();
??????? $result['totalnum']=$res['totalnum'];
??????? $result['integral']=$in['integral'];
??????? return $this->render('index',['result'=>$result,'region'=>$region]);
??? }
?
??? public function actionIndex($id)
??? {
??????? $result = Login::find()->where(['id'=>$id])->asArray()->one();
??????? $res = Sign::find()->where(['u_id'=>$id])->asArray()->one();
??????? $in = Integral::find()->where(['id'=>$id])->asArray()->one();
??????? $region = Region::find()->where(['parent_id'=>0])->asArray()->all();
??????? $result['totalnum']=$res['totalnum'];
??????? $result['integral']=$in['integral'];
??????? return $this->render('index',['result'=>$result,'region'=>$region]);
??? }
??????? // 地區聯動
??????? public function actionRegion()
??????? {
??????????? $parent_id=Yii::$app->request->post('region_id');
??????????? $region = Region::find()->where(['parent_id'=>$parent_id])->asArray()->all();
??????????? exit(json_encode($region));
??????? }
轉載于:https://www.cnblogs.com/sensai-sun/p/6732565.html
總結
以上是生活随笔為你收集整理的yii2地址多级联动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 利用SQL模糊匹配来验证字段是否是日期格
- 下一篇: [050] 微信公众平台开发入门视频教程