<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 actionRegion()
{
$parent_id=Yii::$app->request->post('region_id');
$region = Region::find()->where(['parent_id'=>$parent_id])->asArray()->all();
exit(json_encode($region));
}