index.js
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from "react";
export default class Select extends React.Component {
constructor(props) {
super(props);
this.state = {
projects: [],
value: 1
};
}
componentDidMount() {
console.log(this.props.list);
this.setState({
projects: this.props.list,
value: 1
});
}
handleClick() {
this.setState({
projects: [
{ id: 4, name: "水果" },
{ id: 5, name: "西瓜" },
{ id: 6, name: "哈哈哈" }
],
value: 4
});
}
handleChange = e => {
this.setState({
value: e.target.value
});
this.props.changeValue(e.target.value)
console.log(e.target.value);
};
render() {
let projects = this.state.projects;
return (
<div>
<select
value={this.state.value}
onChange={this.handleChange}
>
{projects.length > 0 &&
projects.map((item, i) => {
return (
<option key={i} value={item.name}>
{item.name}
</option>
);
})}
</select>
</div>
);
}
}