ReactJS : Bootstrap List Example














Demo Code Download .

Javascript/JSX(app.js):

  1. 'use strict';
  2. // lets populate list with this JSON array dynamically
  3. var data = [
  4. {author: "Pete Hunt", text: "This is one comment"},
  5. {author: "Jordan Walke", text: "This is *another* comment"},
  6. {author: "Pete Hunt", text: "This is second comment"}
  7. ];
  8. var Comment = React.createClass({
  9. render: function() {
  10. return (
  11. <li className="list-group-item">
  12. <b>{this.props.text}</b> : by - <span className="author-look">{this.props.author}</span>
  13. </li>
  14. );
  15. }
  16. });
  17. var CommentList = React.createClass({
  18. render: function() {
  19. var commentNodes = this.props.data.map(function (comment) {
  20. return (
  21. <Comment author={comment.author} text={comment.text}></Comment>
  22. );
  23. });
  24. return (
  25. <ul className="list-group list-look">
  26. {commentNodes}
  27. </ul>
  28. );
  29. }
  30. });
  31. ReactDOM.render(<CommentList data={data}/>, document.getElementById('myListDiv'));

Simplest index.html to get us started :)

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <title>jQuery Integration</title>
  7. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" type="text/css" />
  8. <link rel="stylesheet" href="css/example.css" type="text/css" />
  9. </head>
  10. <body>
  11. <div id="myListDiv"></div>
  12. <script src="https://cdn.jsdelivr.net/react/0.14.0-rc1/react.min.js"></script>
  13. <script src="https://cdn.jsdelivr.net/react/0.14.0-rc1/react-dom.min.js"></script>
  14. <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.min.js"></script>
  15. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js" charset="utf-8"></script>
  16. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js" charset="utf-8"></script>
  17. <script type="text/babel" src="js/app.js"></script>
  18. </body>
  19. </html>




References:
https://facebook.github.io/react/docs/tutorial.html#hook-up-the-data-model

No comments:

Post a Comment