let result;
if(this.state.mark.length === 0){
result= <p>Привет</p>
}else{
result=<p>{this.state.mark[0]}</p>
}
change(e){
let unit = e.target.value;
let arr = this.state.mark;
if(e.currentTarget.checked === true){
arr.push(unit);
this.setState=({mark: arr});
}else{
arr.splice(arr.indexOf(unit), 1);
this.setState=({mark: arr});
}
}
import React from "react";
import Model from "./model";
class Main extends React.Component {
constructor(props){
super(props);
this.state = {
WeatherObj:null,
mark:[],
stylecontainerinput:{
display:"flex",
flexDirection:"column"
},
stylelabel:{
font: "15px Arial"
},
header:{
font: "15px Arial"
}
}
}
change(e){
let unit = e.target.value;
let arr = this.state.mark;
if(e.currentTarget.checked === true){
arr.push(unit);
this.setState=({mark: arr});
}else{
arr.splice(arr.indexOf(unit), 1);
this.setState=({mark: arr});
}
}
render() {
let result;
if(this.state.mark.length === 0){
result= <p>Привет</p>
}else{
result=<p>{this.state.mark[0]}</p>
}
return(
<div style={this.state.stylecontainerinput}>
<p style={this.state.header}>Выбрать марку</p>
<div>
<input id="bmw" value="bmw" type="checkbox" onClick={this.change.bind(this)}/>
<label style={this.state.stylelabel} htmlFor="bmw">BMW</label>
</div>
<div>
{result}
</div>
</div>
)
}
}
export default Main;