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

  • 相关阅读:
    lua math 库
    【转】Lua 操作系统库
    lua学习笔记(十三)
    lua学习笔记(十二)
    lua学习笔记(十一)
    lua学习笔记(十)
    lua学习笔记(九)
    lua学习笔记(八)
    lua学习笔记(七)
    lua学习笔记(六)
  • 原文地址:https://www.cnblogs.com/sensai-sun/p/6732565.html
Copyright © 2020-2023  润新知