|
| 1 | +<html> |
| 2 | + <head> |
| 3 | + <title>Reactjs Dev</title> |
| 4 | + <meta name="description" content=""> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 7 | + <!-- Latest compiled and minified CSS --> |
| 8 | + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" /> |
| 9 | + <!-- Title is needed to trigger loading entonejs --> |
| 10 | + </head> |
| 11 | + <body> |
| 12 | + </body> |
| 13 | + <!-- The core React library --> |
| 14 | + <script src="http://fb.me/react-0.12.2.js"></script> |
| 15 | + <!-- In-browser JSX transformer, remove when pre-compiling JSX. --> |
| 16 | + <script src="http://fb.me/JSXTransformer-0.12.2.js"></script> |
| 17 | + <script type="text/jsx"> |
| 18 | + var MyAppComponent = React.createClass({ |
| 19 | + render: function() { |
| 20 | + return ( |
| 21 | + <div className="container"> |
| 22 | + <div className="page-header"> |
| 23 | + <h1>Reactjs Demo Page:</h1> |
| 24 | + <h2 id="helloMsg"> |
| 25 | + <HelloMessage name={this.props.helloMsg}/> |
| 26 | + </h2> |
| 27 | + </div> |
| 28 | + <MyListComponent results={this.props.listItems}/> |
| 29 | + </div> |
| 30 | + ); |
| 31 | + } |
| 32 | + }); |
| 33 | + |
| 34 | + var HelloMessage = React.createClass({ |
| 35 | + render: function() { |
| 36 | + return <small>Hello {this.props.name}!</small>; |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + var ListItemWrapper = React.createClass({ |
| 41 | + render: function() { |
| 42 | + return <li className={this.props.active ? "list-group-item active" : "list-group-item"}>{this.props.data.text}</li>; |
| 43 | + } |
| 44 | + }); |
| 45 | + var MyListComponent = React.createClass({ |
| 46 | + getInitialState: function() { |
| 47 | + return { |
| 48 | + activeIdx: 0 |
| 49 | + } |
| 50 | + }, |
| 51 | + render: function() { |
| 52 | + var activeIdx = this.state.activeIdx; |
| 53 | + return ( |
| 54 | + <ul className="list-group"> |
| 55 | + {this.props.results.map(function(result, idx) { |
| 56 | + return <ListItemWrapper key={result.id} data={result} active={idx === activeIdx}/>; |
| 57 | + })} |
| 58 | + </ul> |
| 59 | + ); |
| 60 | + } |
| 61 | + }); |
| 62 | + |
| 63 | + var myList = [{ |
| 64 | + "id": 1, |
| 65 | + "text": "Cras justo odio" |
| 66 | + },{ |
| 67 | + "id": 2, |
| 68 | + "text": "Dapibus ac facilisis in" |
| 69 | + },{ |
| 70 | + "id": 3, |
| 71 | + "text": "Morbi leo risus" |
| 72 | + },{ |
| 73 | + "id": 4, |
| 74 | + "text": "Porta ac consectetur ac" |
| 75 | + },{ |
| 76 | + "id": 5, |
| 77 | + "text": "Vestibulum at eros" |
| 78 | + }]; |
| 79 | + React.render( |
| 80 | + <MyAppComponent helloMsg="ReactJS" listItems={myList}/>, |
| 81 | + document.body |
| 82 | + ); |
| 83 | + |
| 84 | + </script> |
| 85 | +</html> |
| 86 | + |
0 commit comments