该组件只用于满足很具体的需求,若需要受控组件,推荐使用four-layer-select
基于ant-design的区域选择组件
https://zhaiyb.github.io/region-select/
import 'antd/dist/antd.css';
import RegionSelect from '@bizfe/region-select';
import ReactDom from 'react-dom';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
checkedCities: ['1201']
};
}
handleChange = (value) => {
this.setState({
checkedCities: value
});
};
render() {
const {checkedCities} = this.state;
return (
<div>
<RegionSelect value={checkedCities} onChange={this.handleChange}/>
<label style={{color:"red"}}>checkedCities: </label>{checkedCities.join()}
</div>
);
}
}
ReactDom.render(
<App/>,
document.getElementById('app')
);
- 提供onChange方法,参数为已选择的城市code组成的数组
- 可接受dataSource(所有区域数据)和value(初始选中城市)两个props
- 可用于Form表单包含使用,详见 Ant-design自定义表单控件
- 依赖lodash
参考如下格式
const regionDict = {
"label": "所有地区",
"value": "0",
"regions": [{
"label": "华北地区",
"value": "1",
"provinces": [{
"label": "北京",
"value": "100",
"cities": []
}, {
"label": "天津",
"value": "300",
"cities": []
}, {
"label": "河北",
"value": "1200",
"cities": [{
"label": "石家庄市",
"value": "1201"
}, {
"label": "唐山市",
"value": "1202"
}, {
"label": "秦皇岛市",
"value": "1203"
}, {
"label": "邯郸市",
"value": "1204"
}]
}]
}]
};
- 组件props和onChange中的value均为选中城市的code所构成的数组
- 选中“所有区域”时,value为['0']
- 初始value数组的各项与datasource中各城市value的值统一为String类型