PageRenderTime 35ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/web/com.wordpress.katratxo.mobile.sample1/backbone.html

https://bitbucket.org/iperdomo/com.wordpress.katratxo.mobile.sample1
HTML | 47 lines | 39 code | 8 blank | 0 comment | 0 complexity | de7a68d3c00688bba52e010fa27853cf MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="js/json2.js"></script>
  5. <script src="js/jquery-1.7.1.min.js"></script>
  6. <script src="js/underscore-1.3.1.min.js"></script>
  7. <script src="js/backbone-0.9.1.min.js"></script>
  8. </head>
  9. <body>
  10. <div id="products"></div>
  11. <script>
  12. var Product = Backbone.Model.extend({});
  13. var ProductList = Backbone.Collection.extend({
  14. model: Product,
  15. url: '../../org.openbravo.service.datasource/Product',
  16. parse: function (response, error) {
  17. if (response && response.response) {
  18. return response.response.data;
  19. }
  20. }
  21. });
  22. var Products = new ProductList;
  23. var ProductsView = Backbone.View.extend({
  24. el: '#products',
  25. tag: 'ul',
  26. tpl: "<% _.each(models, function(product) { %> <li><%= product.attributes._identifier %></li> <% }); %>",
  27. initialize: function () {
  28. Products.bind('all', this.render, this);
  29. Products.fetch();
  30. },
  31. render: function (event, collection, error) {
  32. $(this.el).html('<ul>' + _.template(this.tpl, collection) + '</ul>');
  33. return this;
  34. }
  35. });
  36. var App = new ProductsView;
  37. </script>
  38. </body>
  39. </html>