Skip to content

Instantly share code, notes, and snippets.

@arasatasaygin
Created August 7, 2014 13:35
Show Gist options
  • Select an option

  • Save arasatasaygin/9208acf032b8a00ee93b to your computer and use it in GitHub Desktop.

Select an option

Save arasatasaygin/9208acf032b8a00ee93b to your computer and use it in GitHub Desktop.
Render products
var renderSearchedProduct = function(products) {
var Product = Backbone.Model.extend({});
var Products = Backbone.Collection.extend({
model: Product,
initialize: function() {
this.add(products);
}
});
PageData.productCollection = new Products();
var ProductListView = Backbone.View.extend({
el: 'ul.product-list',
initialize: function() {
this.render();
},
render: function() {
var productResults = [];
this.$el.empty();
var template = _.template($("#product-template").html());
PageData.productCollection.each(function(i) {
productResults.push(template(i.toJSON()));
}, this);
this.$el.html(productResults.join(''));
return this;
}
});
var productList = new ProductListView();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment