1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
(function($) {
// Models
window.App = Backbone.Model.extend();
window.AppCollection = Backbone.Collection.extend({
model : App,
url : 'app.php'
});
// Views
window.AppRubricListView = Backbone.View.extend({
el : $('#rub-container'),
initialize : function() {
this.template = _.template($('#rub-template').html());
},
render : function() {
var renderedContent = this.template({ RubricList : this.collection.toJSON() });
$(this.el).html(renderedContent);
return this;
}
});
// Router
var AppRouter = Backbone.Router.extend({
routes : {
"" : "root"
},
root:function() {
this.RubricList = new AppCollection();
this.RubricList.fetch();
this.AppRubricListView = new AppRubricListView({ collection : this.RubricList });
this.AppRubricListView.render();
}
});
var router = new AppRouter();
Backbone.history.start();
})(jQuery); |