ant-design/components/select/demo/coordinate.md
Marius Ileana a8cc57cd13 docs: select/demo/coordinate.md - English translation (#3011)
English translation of labels/data
2016-09-12 10:10:27 +08:00

66 lines
1.6 KiB
Markdown

---
order: 6
title:
zh-CN: 联动
en-US: coordinate
---
## zh-CN
省市联动是典型的例子。
推荐使用 [Cascader](/components/cascader/) 组件。
## 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.
````jsx
import { Select } from 'antd';
const Option = Select.Option;
const provinceData = ['Zhejiang', 'Jiangsu'];
const cityData = {
Zhejiang: ['Hangzhou', 'Ningbo', 'Wenzhou'],
Jiangsu: ['Nanjing', 'Suzhou', 'Zhenjiang'],
};
const App = React.createClass({
getInitialState() {
return {
cities: cityData[provinceData[0]],
secondCity: cityData[provinceData[0]][0],
};
},
handleProvinceChange(value) {
this.setState({
cities: cityData[value],
secondCity: cityData[value][0],
});
},
onSecondCityChange(value) {
this.setState({
secondCity: value,
});
},
render() {
const provinceOptions = provinceData.map(province => <Option key={province}>{province}</Option>);
const cityOptions = this.state.cities.map(city => <Option key={city}>{city}</Option>);
return (
<div>
<Select defaultValue={provinceData[0]} style={{ width: 90 }} onChange={this.handleProvinceChange}>
{provinceOptions}
</Select>
<Select value={this.state.secondCity} style={{ width: 90 }} onChange={this.onSecondCityChange}>
{cityOptions}
</Select>
</div>
);
},
});
ReactDOM.render(<App />, mountNode);
````