组件说明
城市选择组件用于选择省市区,内置中国行政区划数据。
用法示例
use plugin\xbCode\builder\Builder;
use plugin\xbCode\builder\Renders\Form;
Builder::form(function (Form $builder) {
// 基础用法
$builder->addRowCity('city', '城市', '', function($component) {
$component->allowCity(true);
$component->allowDistrict(true);
$component->extractValue(false); // 返回对象包含code、province、city、district
});
// 只返回code
$builder->addRowCity('area_code', '地区', '', [
'searchable' => true,
'extractValue' => true, // 只返回code值
'required' => true
]);
});
组件参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | string | - | 字段名称 |
| label | string | - | 字段标签 |
| value | mixed | - | 默认值 |
| itemClassName | string | - | 子项类名称 |
| allowCity | bool | true | 是否允许选择城市 |
| allowDistrict | bool | true | 是否允许选择区域 |
| searchable | bool | false | 是否显示搜索框 |
| extractValue | bool | false | 是否只提取code值。false时返回包含code、province、city、district的对象 |
| required | bool | false | 是否必填 |
| disabled | bool | false | 是否禁用 |
使用说明
- extractValue为false时,返回格式:
{code: '440106', province: '广东省', city: '广州市', district: '天河区'} - extractValue为true时,只返回code:
'440106' - allowCity和allowDistrict控制选择的粒度
- searchable开启后可以快速搜索城市