2016-07-25 17:46:45 +08:00
|
|
|
---
|
|
|
|
order: 0
|
2016-08-23 21:00:35 +08:00
|
|
|
title:
|
2016-07-25 17:46:45 +08:00
|
|
|
zh-CN: 基本使用
|
|
|
|
en-US: Basic Usage
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
基本使用。通过 dataSource 设置自动完成的数据源
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2019-08-23 12:18:27 +08:00
|
|
|
Basic Usage, set data source of autocomplete with `dataSource` property.
|
2016-07-25 17:46:45 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
```jsx
|
2016-07-25 17:46:45 +08:00
|
|
|
import { AutoComplete } from 'antd';
|
|
|
|
|
2016-10-08 11:20:53 +08:00
|
|
|
function onSelect(value) {
|
|
|
|
console.log('onSelect', value);
|
|
|
|
}
|
|
|
|
|
2017-02-19 20:12:41 +08:00
|
|
|
class Complete extends React.Component {
|
|
|
|
state = {
|
2019-08-23 12:18:27 +08:00
|
|
|
value: '',
|
2017-02-19 20:12:41 +08:00
|
|
|
dataSource: [],
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2017-02-19 20:12:41 +08:00
|
|
|
|
2019-08-23 12:18:27 +08:00
|
|
|
onSearch = searchText => {
|
2016-07-25 17:46:45 +08:00
|
|
|
this.setState({
|
2019-08-23 12:18:27 +08:00
|
|
|
dataSource: !searchText ? [] : [searchText, searchText.repeat(2), searchText.repeat(3)],
|
2016-07-25 17:46:45 +08:00
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2017-02-19 20:12:41 +08:00
|
|
|
|
2019-08-23 12:18:27 +08:00
|
|
|
onChange = value => {
|
|
|
|
this.setState({ value });
|
|
|
|
};
|
|
|
|
|
2016-07-25 17:46:45 +08:00
|
|
|
render() {
|
2019-08-23 12:18:27 +08:00
|
|
|
const { dataSource, value } = this.state;
|
2016-09-21 17:14:58 +08:00
|
|
|
return (
|
2019-08-23 12:18:27 +08:00
|
|
|
<div>
|
|
|
|
<AutoComplete
|
|
|
|
dataSource={dataSource}
|
|
|
|
style={{ width: 200 }}
|
|
|
|
onSelect={onSelect}
|
|
|
|
onSearch={this.onSearch}
|
|
|
|
placeholder="input here"
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<AutoComplete
|
|
|
|
value={value}
|
|
|
|
dataSource={dataSource}
|
|
|
|
style={{ width: 200 }}
|
|
|
|
onSelect={onSelect}
|
|
|
|
onSearch={this.onSearch}
|
|
|
|
onChange={this.onChange}
|
|
|
|
placeholder="control mode"
|
|
|
|
/>
|
|
|
|
</div>
|
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);
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|