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
|
|
|
|
|
|
|
|
Basic Usage, set datasource of autocomplete with `dataSource` property.
|
|
|
|
|
2017-02-13 10:55:53 +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 = {
|
|
|
|
dataSource: [],
|
|
|
|
}
|
|
|
|
|
2017-04-13 11:11:24 +08:00
|
|
|
handleSearch = (value) => {
|
2016-07-25 17:46:45 +08:00
|
|
|
this.setState({
|
2016-09-19 17:08:18 +08:00
|
|
|
dataSource: !value ? [] : [
|
2016-07-25 17:46:45 +08:00
|
|
|
value,
|
|
|
|
value + value,
|
|
|
|
value + value + value,
|
|
|
|
],
|
|
|
|
});
|
2017-02-19 20:12:41 +08:00
|
|
|
}
|
|
|
|
|
2016-07-25 17:46:45 +08:00
|
|
|
render() {
|
|
|
|
const { dataSource } = this.state;
|
2016-09-21 17:14:58 +08:00
|
|
|
return (
|
|
|
|
<AutoComplete
|
|
|
|
dataSource={dataSource}
|
|
|
|
style={{ width: 200 }}
|
2016-10-08 11:20:53 +08:00
|
|
|
onSelect={onSelect}
|
2017-04-13 11:11:24 +08:00
|
|
|
onSearch={this.handleSearch}
|
2016-12-03 15:28:47 +08:00
|
|
|
placeholder="input here"
|
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);
|
|
|
|
````
|