2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 6
|
2016-07-10 08:55:43 +08:00
|
|
|
title:
|
|
|
|
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-05-13 23:10:05 +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.
|
|
|
|
|
|
|
|
|
2015-08-06 12:06:05 +08:00
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { Select } from 'antd';
|
|
|
|
const Option = Select.Option;
|
2015-08-06 12:06:05 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const provinceData = ['浙江', '江苏'];
|
|
|
|
const cityData = {
|
2016-02-16 14:07:09 +08:00
|
|
|
浙江: ['杭州', '宁波', '温州'],
|
2016-05-11 09:32:33 +08:00
|
|
|
江苏: ['南京', '苏州', '镇江'],
|
2015-08-06 12:06:05 +08:00
|
|
|
};
|
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const App = React.createClass({
|
2015-08-06 12:06:05 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
2015-08-20 17:27:40 +08:00
|
|
|
cities: cityData[provinceData[0]],
|
2016-05-11 09:32:33 +08:00
|
|
|
secondCity: cityData[provinceData[0]][0],
|
2015-08-06 12:06:05 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
handleProvinceChange(value) {
|
|
|
|
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
|
|
|
});
|
|
|
|
},
|
|
|
|
onSecondCityChange(value) {
|
|
|
|
this.setState({
|
2016-05-11 09:32:33 +08:00
|
|
|
secondCity: value,
|
2015-08-06 12:06:05 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
render() {
|
2016-01-23 15:22:16 +08:00
|
|
|
const provinceOptions = provinceData.map(province => <Option key={province}>{province}</Option>);
|
|
|
|
const cityOptions = this.state.cities.map(city => <Option key={city}>{city}</Option>);
|
2016-01-07 16:29:12 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-01-27 16:44:50 +08:00
|
|
|
<Select defaultValue={provinceData[0]} style={{ width: 90 }} onChange={this.handleProvinceChange}>
|
2016-01-07 16:29:12 +08:00
|
|
|
{provinceOptions}
|
|
|
|
</Select>
|
2016-01-27 16:44:50 +08:00
|
|
|
<Select value={this.state.secondCity} style={{ width: 90 }} onChange={this.onSecondCityChange}>
|
2016-01-07 16:29:12 +08:00
|
|
|
{cityOptions}
|
|
|
|
</Select>
|
|
|
|
</div>
|
|
|
|
);
|
2016-05-11 09:32:33 +08:00
|
|
|
},
|
2015-08-06 12:06:05 +08:00
|
|
|
});
|
2015-12-29 12:08:58 +08:00
|
|
|
ReactDOM.render(<App />, mountNode);
|
2015-08-06 12:06:05 +08:00
|
|
|
````
|