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_knockout.html 1016B

123456789101112131415161718192021222324252627282930313233
  1. <html>
  2. <head>
  3. <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
  5. <script src="../lib/php_crud_api_transform.js"></script>
  6. <script>
  7. var url = '../api.php/posts';
  8. function PostList(){
  9. var self = this;
  10. self.posts = ko.observableArray([]);
  11. self.set = function(array) {
  12. self.posts.removeAll();
  13. for (i=0;i<array.length;i++) {
  14. self.posts.push(array[i]);
  15. }
  16. };
  17. self.update = function() {
  18. $.get(url, function(data) {
  19. self.set(php_crud_api_transform(data).posts);
  20. });
  21. };
  22. $.post(url, {user_id:1,category_id:1,content:"from knockout"}, self.update.bind(self));
  23. };
  24. $(function(){
  25. $('#myApplication').html('<ul data-bind="foreach: posts"><li><span data-bind="text: id"></span>, <span data-bind="text: content"></span></li></ul>');
  26. ko.applyBindings(new PostList(),$('#myApplication')[0]);
  27. });
  28. </script>
  29. </head>
  30. <body>
  31. <div id="myApplication">Loading...</div>
  32. </body>
  33. </html>