Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Test = React.createClass({
- getInitialState: function () {
- return {
- myArr: [
- { id: '0', name: "test1", age: 26, address: "X city" },
- { id: '1', name: "test2", age: 19, address: "Y city" },
- { id: '2', name: "test3", age: 35, address: "Z city" },
- ]
- }
- },
- addNewObject: function () {
- var arr = this.state.myArr;
- arr[3].push({
- name: this.refs.value.newName,
- age: this.refs.value.newAge,
- address: this.refs.value.newAddress,
- id: 3,
- });
- this.setState({ participants: arr });
- console.log(arr[3]);
- },
- onSubmit: function (e) {
- e.preventDefault();
- },
- render: function () {
- return (
- <div>
- <form onSubmit={this.onSubmit}>
- <input ref="newName" type="text" placeholder="Full name" />
- <input ref="newAge" type="number" placeholder="Age" />
- <input ref="newAddress" type="tel" placeholder="Address" />
- <input onClick={this.addNewObject} type="submit" value="Add new" />
- </form>
- </div>
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement