Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. var Test = React.createClass({
  2. getInitialState: function () {
  3. return {
  4. myArr: [
  5. { id: '0', name: "test1", age: 26, address: "X city" },
  6. { id: '1', name: "test2", age: 19, address: "Y city" },
  7. { id: '2', name: "test3", age: 35, address: "Z city" },
  8. ]
  9. }
  10.  
  11. },
  12.  
  13.  
  14. addNewObject: function () {
  15. var arr = this.state.myArr;
  16. arr[3].push({
  17.  
  18. name: this.refs.value.newName,
  19. age: this.refs.value.newAge,
  20. address: this.refs.value.newAddress,
  21. id: 3,
  22. });
  23. this.setState({ participants: arr });
  24. console.log(arr[3]);
  25. },
  26.  
  27. onSubmit: function (e) {
  28. e.preventDefault();
  29.  
  30. },
  31.  
  32. render: function () {
  33. return (
  34. <div>
  35. <form onSubmit={this.onSubmit}>
  36. <input ref="newName" type="text" placeholder="Full name" />
  37. <input ref="newAge" type="number" placeholder="Age" />
  38. <input ref="newAddress" type="tel" placeholder="Address" />
  39. <input onClick={this.addNewObject} type="submit" value="Add new" />
  40. </form>
  41. </div>
  42.  
  43. );
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement