城市选择组件

组件说明

城市选择组件用于选择省市区,内置中国行政区划数据。

用法示例

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

组件参数

参数名类型默认值说明
namestring-字段名称
labelstring-字段标签
valuemixed-默认值
itemClassNamestring-子项类名称
allowCitybooltrue是否允许选择城市
allowDistrictbooltrue是否允许选择区域
searchableboolfalse是否显示搜索框
extractValueboolfalse是否只提取code值。false时返回包含code、province、city、district的对象
requiredboolfalse是否必填
disabledboolfalse是否禁用

使用说明

  1. extractValue为false时,返回格式:{code: '440106', province: '广东省', city: '广州市', district: '天河区'}
  2. extractValue为true时,只返回code:'440106'
  3. allowCity和allowDistrict控制选择的粒度
  4. searchable开启后可以快速搜索城市