2016-07-25 17:46:45 +08:00
|
|
|
---
|
|
|
|
order: 2
|
2016-08-23 21:00:35 +08:00
|
|
|
title:
|
2016-07-25 17:46:45 +08:00
|
|
|
zh-CN: 自定义选项
|
|
|
|
en-US: Customized
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
Datasource 的每一项是一个 `AutoComplete.Option`。通过 `AutoComplete.Option` 自定义下拉菜单。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2016-07-25 17:54:09 +08:00
|
|
|
Items in dataSource could be an `AutoComplete.Option`.
|
|
|
|
|
2016-07-25 17:46:45 +08:00
|
|
|
|
|
|
|
````jsx
|
|
|
|
import { AutoComplete } from 'antd';
|
2016-08-23 21:00:35 +08:00
|
|
|
|
2016-07-25 17:46:45 +08:00
|
|
|
const Option = AutoComplete.Option;
|
|
|
|
|
|
|
|
const Complete = React.createClass({
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
dataSource: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
handleChange(value) {
|
|
|
|
let dataSource;
|
|
|
|
if (!value || value.indexOf('@') >= 0) {
|
|
|
|
dataSource = [];
|
|
|
|
} else {
|
|
|
|
dataSource = ['gmail.com', '163.com', 'qq.com'].map((domain) => {
|
|
|
|
const email = `${value}@${domain}`;
|
|
|
|
return <Option key={email}>{email}</Option>;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.setState({ dataSource });
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
const { dataSource } = this.state;
|
|
|
|
return (<AutoComplete
|
|
|
|
style={{ width: 200 }}
|
|
|
|
dataSource={dataSource}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
/>);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
ReactDOM.render(<Complete />, mountNode);
|
|
|
|
````
|