Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. Object {1: Object, 2: Object, 3: Object, 4: Object, 5: Object, 6: Object}
  2.  
  3. 1 capital_payment :"100",
  4. currency: "2"
  5. dudedate : "2017-08-20"
  6.  
  7. var Heading = React.createClass({
  8. getInitialState: function() {
  9. return {
  10. data : [],
  11. amount : 1000,
  12. firstMonth : 0,
  13. showtable : false <--------- HERE IS THE SHOW TABLE STATE
  14. };
  15. },
  16. showTable : function(){
  17. console.log('I am here');
  18. this.setState({showtable : !this.state.showtable}); <----CHANGING STATE HERE
  19. console.log(this.state.showtable);
  20. },
  21. render : function(){
  22. var amount = this.state.amount;
  23. var firstMonth = this.state.firstMonth;
  24. return(
  25. <div className="container">
  26. <div className="row">
  27. <div className="col-xs-4 col-xs-offset-4">
  28. <div className="form-group">
  29. <label>How much <span>{amount}</span> </label>
  30. <input type="text" className="form-control" placeholder="Amount" value={amount} onChange={this.handleChange} />
  31. </div>
  32. <button type="submit" className="btn btn-success" onClick={this.loadCommentsFromServer} >Submit</button>
  33. <button type="submit" className="btn btn-success" onClick = {this.showTable} > Show table </button>
  34. <hr />
  35. <!--- HERE IS WHERE THE NEW CLASS SHOULD SHOW UP IF TABLE IS CHANGED -->
  36. { this.state.showtable ? <tableView data={this.state.data}/> : null }
  37. </div>
  38. </div>
  39. </div>
  40. );
  41. }
  42. });
  43. // HERE IS THE TABLEVIEW, AND I HAVE NO CLUE HOW TO DO A FOR LOOP TO RENDER INFORMATION TO THE TABLE
  44. var tableView = React.createClass({
  45. render: function() {
  46. console.log(this.props.data);
  47. return (
  48. <table className="table">
  49. <thead>
  50. <tr>
  51. <th>amount</th>
  52. <th>duedate</th>
  53. <th>currency</th>
  54. </tr>
  55. </thead>
  56. <tbody>
  57. <tr>
  58. <!-- Need to know how the forloop is done, is there a easier way? -->
  59. {this.props.data.map(function(info) {
  60. return (
  61. <tr key={info}>
  62. {info.capital_payment},
  63. {info.currency},
  64. {info.duedate}
  65. </tr>
  66. );
  67. })}
  68. </tr>
  69. </tbody>
  70. </table>
  71. );
  72. }
  73. });
  74.  
  75.  
  76. ReactDOM.render(
  77. <div>
  78. <Heading
  79. name="React JS"
  80. >
  81. </Heading>
  82. <tableView />
  83. </div>
  84. , document.getElementById('reactBinding'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement