You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.0 KiB

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