Created
November 24, 2015 05:56
-
-
Save AllenFang/dff2b56a8d77575b2747 to your computer and use it in GitHub Desktop.
reactjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var RadioGroup = React.createClass({ | |
| getInitialState: function () { | |
| return { | |
| select: null | |
| }; | |
| }, | |
| handleRdioBtnChange: function(e){ | |
| this.setState({ | |
| select: e.currentTarget.value; | |
| }); | |
| }, | |
| render: function () { | |
| var radioBtns = this.props.options.map(function(option){ | |
| var isActive = this.state.select === option?"active":""; | |
| return( | |
| <label className="radio-inline"> | |
| <input type="radio" onChange={this.handleRdioBtnChange.bind(this)} value={option} className={isActive}/> | |
| {option} | |
| </label> | |
| ); | |
| }, this); | |
| return ( | |
| <div> | |
| {radioBtns} | |
| </div> | |
| ); | |
| } | |
| }); | |
| var opptions = ["A", "B", "C"]; //<< it's your radiogroups | |
| React.renderComponent(<RadioGroup options={opptions} />, document.getElementById('example')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment