2016-03-31 09:40:55 +08:00
|
|
|
---
|
2018-05-21 17:07:39 +08:00
|
|
|
order: 7
|
2017-02-20 21:54:23 +08:00
|
|
|
title:
|
2016-07-10 08:55:43 +08:00
|
|
|
zh-CN: 联动
|
|
|
|
en-US: coordinate
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-08-06 12:06:05 +08:00
|
|
|
|
2016-07-10 08:55:43 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-08-06 12:06:05 +08:00
|
|
|
省市联动是典型的例子。
|
|
|
|
|
2016-08-25 10:52:51 +08:00
|
|
|
推荐使用 [Cascader](/components/cascader/) 组件。
|
2016-03-31 09:40:55 +08:00
|
|
|
|
2016-07-10 08:55:43 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
Coordinating the selection of provinces and cities is a common use case and demonstrates how selection can be coordinated.
|
|
|
|
|
|
|
|
Using the [Cascader](/components/cascader) component is strongly recommended instead as it is more flexible and capable.
|
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { Select } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-27 21:32:45 +08:00
|
|
|
const { Option } = Select;
|
2016-09-12 10:10:27 +08:00
|
|
|
const provinceData = ['Zhejiang', 'Jiangsu'];
|
2015-10-28 20:55:49 +08:00
|
|
|
const cityData = {
|
2016-09-12 10:10:27 +08:00
|
|
|
Zhejiang: ['Hangzhou', 'Ningbo', 'Wenzhou'],
|
|
|
|
Jiangsu: ['Nanjing', 'Suzhou', 'Zhenjiang'],
|
2015-08-06 12:06:05 +08:00
|
|
|
};
|
|
|
|
|
2017-02-20 21:54:23 +08:00
|
|
|
class App extends React.Component {
|
|
|
|
state = {
|
|
|
|
cities: cityData[provinceData[0]],
|
|
|
|
secondCity: cityData[provinceData[0]][0],
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
handleProvinceChange = value => {
|
2015-08-06 12:06:05 +08:00
|
|
|
this.setState({
|
2015-08-20 17:27:40 +08:00
|
|
|
cities: cityData[value],
|
2016-05-11 09:32:33 +08:00
|
|
|
secondCity: cityData[value][0],
|
2015-08-20 17:27:40 +08:00
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
onSecondCityChange = value => {
|
2015-08-20 17:27:40 +08:00
|
|
|
this.setState({
|
2016-05-11 09:32:33 +08:00
|
|
|
secondCity: value,
|
2015-08-06 12:06:05 +08:00
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2015-08-06 12:06:05 +08:00
|
|
|
render() {
|
2018-10-06 18:58:25 +08:00
|
|
|
const { cities } = this.state;
|
2016-01-07 16:29:12 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2018-10-06 18:58:25 +08:00
|
|
|
<Select
|
|
|
|
defaultValue={provinceData[0]}
|
|
|
|
style={{ width: 120 }}
|
|
|
|
onChange={this.handleProvinceChange}
|
|
|
|
>
|
2019-05-07 14:57:32 +08:00
|
|
|
{provinceData.map(province => (
|
|
|
|
<Option key={province}>{province}</Option>
|
|
|
|
))}
|
2016-01-07 16:29:12 +08:00
|
|
|
</Select>
|
2018-10-06 18:58:25 +08:00
|
|
|
<Select
|
|
|
|
style={{ width: 120 }}
|
|
|
|
value={this.state.secondCity}
|
|
|
|
onChange={this.onSecondCityChange}
|
|
|
|
>
|
2019-05-07 14:57:32 +08:00
|
|
|
{cities.map(city => (
|
|
|
|
<Option key={city}>{city}</Option>
|
|
|
|
))}
|
2016-01-07 16:29:12 +08:00
|
|
|
</Select>
|
|
|
|
</div>
|
|
|
|
);
|
2017-02-20 21:54:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 12:08:58 +08:00
|
|
|
ReactDOM.render(<App />, mountNode);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|