docs: update demos of AutoComplete, close: #3106

This commit is contained in:
Benjy Cui 2016-09-21 17:14:58 +08:00
parent 247757f63f
commit c1d71acfc7
2 changed files with 23 additions and 19 deletions

View File

@ -33,11 +33,13 @@ const Complete = React.createClass({
},
render() {
const { dataSource } = this.state;
return (<AutoComplete
dataSource={dataSource}
style={{ width: 200 }}
onChange={this.handleChange}
/>);
return (
<AutoComplete
dataSource={dataSource}
style={{ width: 200 }}
onChange={this.handleChange}
/>
);
},
});

View File

@ -22,28 +22,30 @@ const Option = AutoComplete.Option;
const Complete = React.createClass({
getInitialState() {
return {
dataSource: [],
result: [],
};
},
handleChange(value) {
let dataSource;
let result;
if (!value || value.indexOf('@') >= 0) {
dataSource = [];
result = [];
} else {
dataSource = ['gmail.com', '163.com', 'qq.com'].map((domain) => {
const email = `${value}@${domain}`;
return <Option key={email}>{email}</Option>;
});
result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
}
this.setState({ dataSource });
this.setState({ result });
},
render() {
const { dataSource } = this.state;
return (<AutoComplete
style={{ width: 200 }}
dataSource={dataSource}
onChange={this.handleChange}
/>);
const { result } = this.state;
const dataSource = result.map((email) => {
return <Option key={email}>{email}</Option>;
});
return (
<AutoComplete
style={{ width: 200 }}
dataSource={dataSource}
onChange={this.handleChange}
/>
);
},
});