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

54 lines
930 B
Markdown
Raw Normal View History

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.
````jsx
import { AutoComplete } from 'antd';
function onSelect(value) {
console.log('onSelect', value);
}
2016-07-25 17:46:45 +08:00
const Complete = React.createClass({
getInitialState() {
return {
dataSource: [],
};
},
handleChange(value) {
this.setState({
dataSource: !value ? [] : [
2016-07-25 17:46:45 +08:00
value,
value + value,
value + value + value,
],
});
},
render() {
const { dataSource } = this.state;
return (
<AutoComplete
dataSource={dataSource}
style={{ width: 200 }}
onSelect={onSelect}
onChange={this.handleChange}
placeholder="input here"
/>
);
2016-07-25 17:46:45 +08:00
},
});
ReactDOM.render(<Complete />, mountNode);
````