美文网首页
三级联动地址树状数据

三级联动地址树状数据

作者: HongXunPan | 来源:发表于2017-11-11 16:02 被阅读0次

//查询三级联动的地址信息树状结构--未应用

public static functiongetRegionAddressTree()

{

$addressList=self::find()->with([

'children',

'children.children',

])->where([self::tableName().'.parent_id'=>1])->asArray()

->all();

$provinceList= [];

foreach($addressListas$province) {

$cityList= [];

if(!empty($province['children'])) {

foreach($province['children']as$city) {

$districtlist= [];

if(!empty($city['children'])) {

foreach($city['children']as$district) {

$districtlist[] = [

'district_id'=>$district['region_id'],

'district_name'=>$district['region_name'],

];

}

}

$cityList[] = [

'city_id'=>$city['region_id'],

'city_name'=>$city['region_name'],

'district_list'=>$districtlist,

];

}

}

$provinceList[] = [

'province_id'=>$province['region_id'],

'province_name'=>$province['region_name'],

'city_list'=>$cityList,

];

}

return$provinceList;

}


相关文章

网友评论

      本文标题:三级联动地址树状数据

      本文链接:https://www.haomeiwen.com/subject/ciawmxtx.html