I can’t understand why the render method doesn’t fired ? but if i put in the console categoriesView.render() , everything works.
var Category = Backbone.Model.extend();
var Categories = Backbone.Collection.extend({
url: '/data.json',
initialize: function(){
this.fetch();
},
model: Category
});
var CategoryView = Backbone.View.extend({
tagName: 'li',
template: _.template($('.template').html()),
render: function(){
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
var CategoriesView = Backbone.View.extend({
tagName: 'ul',
initialize: function() {
this.render();
},
render: function(){
this.collection.each(function(data){
var categoryView = new CategoryView({model: data});
this.$el.append(categoryView.render().el);
}, this);
return this;
}
});
var category = new Category();
var categories = new Categories();
var categoriesView = new CategoriesView({collection: categories});
categoriesView.render();
$('body').append(categoriesView.el);