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
|
|
|
|
|
2016-09-22 14:40:34 +08:00
|
|
|
也可以直接传 `AutoComplete.Option` 作为 `AutoComplete` 的 `children`,而非使用 `dataSource`。
|
2016-07-25 17:46:45 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2016-09-22 14:40:34 +08:00
|
|
|
You could pass `AutoComplete.Option` as children of `AutoComplete`, instead of using `dataSource`。
|
2016-07-25 17:46:45 +08:00
|
|
|
|
2017-02-13 10:55:53 +08:00
|
|
|
````jsx
|
2016-07-25 17:46:45 +08:00
|
|
|
import { AutoComplete } from 'antd';
|
2016-08-23 21:00:35 +08:00
|
|
|
|
2016-07-25 17:46:45 +08:00
|
|
|
const Option = AutoComplete.Option;
|
|
|
|
|
2017-02-19 20:12:41 +08:00
|
|
|
class Complete extends React.Component {
|
|
|
|
state = {
|
|
|
|
result: [],
|
|
|
|
}
|
|
|
|
|
2017-04-13 11:11:24 +08:00
|
|
|
handleSearch = (value) => {
|
2016-09-21 17:14:58 +08:00
|
|
|
let result;
|
2016-07-25 17:46:45 +08:00
|
|
|
if (!value || value.indexOf('@') >= 0) {
|
2016-09-21 17:14:58 +08:00
|
|
|
result = [];
|
2016-07-25 17:46:45 +08:00
|
|
|
} else {
|
2016-09-21 17:14:58 +08:00
|
|
|
result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
|
2016-07-25 17:46:45 +08:00
|
|
|
}
|
2016-09-21 17:14:58 +08:00
|
|
|
this.setState({ result });
|
2017-02-19 20:12:41 +08:00
|
|
|
}
|
|
|
|
|
2016-07-25 17:46:45 +08:00
|
|
|
render() {
|
2016-09-21 17:14:58 +08:00
|
|
|
const { result } = this.state;
|
2018-11-28 15:00:03 +08:00
|
|
|
const children = result.map(email => <Option key={email}>{email}</Option>);
|
2016-09-21 17:14:58 +08:00
|
|
|
return (
|
|
|
|
<AutoComplete
|
|
|
|
style={{ width: 200 }}
|
2017-04-13 11:11:24 +08:00
|
|
|
onSearch={this.handleSearch}
|
2016-12-03 15:28:47 +08:00
|
|
|
placeholder="input here"
|
2016-09-22 14:40:34 +08:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</AutoComplete>
|
2016-09-21 17:14:58 +08:00
|
|
|
);
|
2017-02-19 20:12:41 +08:00
|
|
|
}
|
|
|
|
}
|
2016-07-25 17:46:45 +08:00
|
|
|
|
|
|
|
ReactDOM.render(<Complete />, mountNode);
|
|
|
|
````
|