我试图通过按钮单击(用于更改状态)提交一个值。它工作正常,如果我只是使用HTML input
元素。但是,如果我使用Material UIRaisedButton
,我根本无法传递值。请帮我指出我做错了什么。ReactJS上的材质UI:`evt.target.value`不适用于`RaisedButton`
这就是所谓的按一下按钮的功能:
changeGameStatus = (evt) => {
let status = ""
switch (evt.target.value) {
case "Start":
status = "in-progress"
break
default:
status = "ready"
break
}
this.setState({
game: {
status: status
}
})
/*when using <RaisedButton>, this.state.game.status returns "undefined"*/
console.log('new status:' + this.state.game.status)
} /* END changeGameStatus */
按钮里面render()
:
/*this one does not send a value at all*/
<RaisedButton onClick={this.changeGameStatus} value="Start" label="Start" primary={true} />
/* this one works, but the look is not supported by material-ui*/
<input type="button" onClick={this.changeGameStatus} value="Start" />
你可以直接传递值onClick事件像这样:onClick = {()=> this.changeGameStatus('Start') }'可能RaisedButton不接受道具的'价值'。 –