ant-design/components/auto-complete/demo/options.md

54 lines
1.1 KiB
Markdown
Raw Normal View History

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
也可以直接传 `AutoComplete.Option` 作为 `AutoComplete``children`,而非使用 `dataSource`
2016-07-25 17:46:45 +08:00
## en-US
You could pass `AutoComplete.Option` as children of `AutoComplete`, instead of using `dataSource`
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 {
result: [],
2016-07-25 17:46:45 +08:00
};
},
handleChange(value) {
let result;
2016-07-25 17:46:45 +08:00
if (!value || value.indexOf('@') >= 0) {
result = [];
2016-07-25 17:46:45 +08:00
} else {
result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
2016-07-25 17:46:45 +08:00
}
this.setState({ result });
2016-07-25 17:46:45 +08:00
},
render() {
const { result } = this.state;
const children = result.map((email) => {
return <Option key={email}>{email}</Option>;
});
return (
<AutoComplete
style={{ width: 200 }}
onChange={this.handleChange}
>
{children}
</AutoComplete>
);
2016-07-25 17:46:45 +08:00
},
});
ReactDOM.render(<Complete />, mountNode);
````