Hul*_*ash 1 html javascript jsx reactjs
我有一个 Button 组件,如果状态为“true”,我想为其分配一个活动类。
<Button
onClick={this.preferenceHandler.bind(this, "straight")}
className={"col-sm-12 text-center " + (this.state.straight ? "active") }
viewStyle= "primary"
>
<h4>Straight</h4>
<i className="icon icon-ok-6"></i>
</Button>
Run Code Online (Sandbox Code Playgroud)
你需要那里的错误表达:
className={"col-sm-12 text-center " + (this.state.straight ? "active" : "") }
Run Code Online (Sandbox Code Playgroud)