api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client_react.html 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <html>
  2. <head>
  3. <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.0/react.js"></script>
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.0/react-dom.js"></script>
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
  6. <script src="../lib/php_crud_api_transform.js"></script>
  7. <script>
  8. var PostList = React.createClass({
  9. displayName: 'PostList',
  10. url: '../api.php/posts',
  11. getInitialState: function() {
  12. return { posts: [] };
  13. },
  14. retrieveServerState: function() {
  15. this.serverRequest = $.get(this.url, function (data) {
  16. this.setState(php_crud_api_transform(data));
  17. }.bind(this));
  18. },
  19. componentDidMount: function() {
  20. $.post(this.url, {user_id:1,category_id:1,content:"from react"}, this.retrieveServerState);
  21. },
  22. componentWillUnmount: function() {
  23. this.serverRequest.abort();
  24. },
  25. render: function render() {
  26. var createPost = function(post) {
  27. return React.createElement(
  28. 'li',
  29. {key: post.id},
  30. post.id,
  31. ', ',
  32. post.content
  33. );
  34. };
  35. return React.createElement(
  36. 'ul',
  37. null,
  38. this.state.posts.map(createPost)
  39. );
  40. }
  41. });
  42. $(function(){ ReactDOM.render(React.createElement(PostList, null), document.getElementById('myApplication')); });
  43. </script>
  44. </head>
  45. <body>
  46. <div id="myApplication">Loading...</div>
  47. </body>
  48. </html>