mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-29 20:08:37 +08:00
07072fc3b1
Related: #5610
54 lines
905 B
Markdown
54 lines
905 B
Markdown
---
|
|
order: 0
|
|
title:
|
|
zh-CN: 基本使用
|
|
en-US: Basic Usage
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
基本使用。通过 dataSource 设置自动完成的数据源
|
|
|
|
## en-US
|
|
|
|
Basic Usage, set datasource of autocomplete with `dataSource` property.
|
|
|
|
````jsx
|
|
import { AutoComplete } from 'antd';
|
|
|
|
function onSelect(value) {
|
|
console.log('onSelect', value);
|
|
}
|
|
|
|
class Complete extends React.Component {
|
|
state = {
|
|
dataSource: [],
|
|
}
|
|
|
|
handleSearch = (value) => {
|
|
this.setState({
|
|
dataSource: !value ? [] : [
|
|
value,
|
|
value + value,
|
|
value + value + value,
|
|
],
|
|
});
|
|
}
|
|
|
|
render() {
|
|
const { dataSource } = this.state;
|
|
return (
|
|
<AutoComplete
|
|
dataSource={dataSource}
|
|
style={{ width: 200 }}
|
|
onSelect={onSelect}
|
|
onSearch={this.handleSearch}
|
|
placeholder="input here"
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<Complete />, mountNode);
|
|
````
|