daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Feb 21st, 2013 142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.Wine = Backbone.Model.extend();
  2.  
  3. //Models
  4.  
  5. window.WineCollection = Backbone.Collection.extend({
  6.     model: Wine,
  7.     url: "../api/wines"
  8.     });
  9. // Views
  10. window.WineListView = Backbone.View.extend({
  11.    
  12.     tagName: 'ul',
  13.  
  14.     intitialize:function() {
  15.         this.model.bind("reset". this.render, this);
  16.     },
  17.  
  18.     render:function (eventName) {
  19.         _.each(this.model.models, function (wine) {
  20.             $(this.el).append(new WineListItemView({model:wine}).render().el);
  21.         }, this);
  22.         return this;
  23.     }
  24.  
  25. });
  26.  
  27. window.WineListItemView = Backbone.View.extend({
  28.  
  29.     tagName: 'li',
  30.  
  31.     template:_.template($('#tpl-wine-details').html()),
  32.  
  33.     render:function (eventName) {
  34.         $(this.el).html(thos.template(this.model.toJSON()));
  35.         return this;
  36.     }
  37. });
  38.  
  39. window.WineView = Backbone.View.extend({
  40.    
  41.     template:_.template($('#tpl-wine-details').html()),
  42.  
  43.     render:function(eventName) {
  44.         $(this.el).html(this.template(this.model.toJSON()));
  45.         return this;
  46.  
  47.     }
  48.  
  49. });
  50.  
  51. //Router
  52. var AppRouter = Backbone.Router.extend({
  53.  
  54.     routes:{
  55.         "":"list",
  56.         "wines/:id":"WineDetails"
  57.     },
  58.  
  59.     list:function () {
  60.         this.wineList = new WineCollection();
  61.         this.WineListView = new WineListView({model:this.wineList});
  62.         this.wineList.fetch();
  63.         $('#sidebar').html(this.wineListView.render().el);
  64.        
  65.     },
  66.  
  67.  
  68.  
  69.     wineDetails: function (id) {
  70.         this.wine = this.wineList.get(id);
  71.         this.wineView = new WineView({model:this.wine});
  72.         $('#content').html(this.wineView.render().el);
  73.     }
  74. });
  75.  
  76. var app = new AppRouter();
  77. Backbone.history.start();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top